ScrollView constructor

const ScrollView(
  1. {Key? key,
  2. Axis scrollDirection = Axis.vertical,
  3. bool reverse = false,
  4. ScrollController? controller,
  5. bool? primary,
  6. ScrollPhysics? physics,
  7. ScrollBehavior? scrollBehavior,
  8. bool shrinkWrap = false,
  9. Key? center,
  10. double anchor = 0.0,
  11. double? cacheExtent,
  12. int? semanticChildCount,
  13. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  14. ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
  15. String? restorationId,
  16. Clip clipBehavior = Clip.hardEdge}
)

Creates a widget that scrolls.

The ScrollView.primary argument defaults to true for vertical scroll views if no controller has been provided. The controller argument must be null if primary is explicitly set to true. If primary is true, the nearest PrimaryScrollController surrounding the widget is attached to this scroll view.

If the shrinkWrap argument is true, the center argument must be null.

The anchor argument must be in the range zero to one, inclusive.

Implementation

const ScrollView({
  super.key,
  this.scrollDirection = Axis.vertical,
  this.reverse = false,
  this.controller,
  this.primary,
  ScrollPhysics? physics,
  this.scrollBehavior,
  this.shrinkWrap = false,
  this.center,
  this.anchor = 0.0,
  this.cacheExtent,
  this.semanticChildCount,
  this.dragStartBehavior = DragStartBehavior.start,
  this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
  this.restorationId,
  this.clipBehavior = Clip.hardEdge,
}) : assert(
       !(controller != null && (primary ?? false)),
       'Primary ScrollViews obtain their ScrollController via inheritance '
       'from a PrimaryScrollController widget. You cannot both set primary to '
       'true and pass an explicit controller.',
     ),
     assert(!shrinkWrap || center == null),
     assert(anchor >= 0.0 && anchor <= 1.0),
     assert(semanticChildCount == null || semanticChildCount >= 0),
     physics = physics ?? ((primary ?? false) || (primary == null && controller == null && identical(scrollDirection, Axis.vertical)) ? const AlwaysScrollableScrollPhysics() : null);