ScrollView constructor Null safety

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

Creates a widget that scrolls.

If the primary argument is true, the controller must be null.

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

The scrollDirection, reverse, and shrinkWrap arguments must not be null.

The anchor argument must be non-null and in the range 0.0 to 1.0.

Implementation

const ScrollView({
  Key? key,
  this.scrollDirection = Axis.vertical,
  this.reverse = false,
  this.controller,
  bool? 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(scrollDirection != null),
     assert(reverse != null),
     assert(shrinkWrap != null),
     assert(dragStartBehavior != null),
     assert(clipBehavior != null),
     assert(!(controller != null && primary == true),
         '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 != null),
     assert(anchor >= 0.0 && anchor <= 1.0),
     assert(semanticChildCount == null || semanticChildCount >= 0),
     primary = primary ?? controller == null && identical(scrollDirection, Axis.vertical),
     physics = physics ?? (primary == true || (primary == null && controller == null && identical(scrollDirection, Axis.vertical)) ? const AlwaysScrollableScrollPhysics() : null),
     super(key: key);