ScrollView constructor Null safety
- {Key? key,
- Axis scrollDirection = Axis.vertical,
- bool reverse = false,
- ScrollController? controller,
- bool? primary,
- ScrollPhysics? physics,
- ScrollBehavior? scrollBehavior,
- bool shrinkWrap = false,
- Key? center,
- double anchor = 0.0,
- double? cacheExtent,
- int? semanticChildCount,
- DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual,
- String? restorationId,
- 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 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 ?? 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 != null),
assert(anchor >= 0.0 && anchor <= 1.0),
assert(semanticChildCount == null || semanticChildCount >= 0),
primary = primary ?? controller == null && identical(scrollDirection, Axis.vertical),
physics = physics ?? ((primary ?? false) || (primary == null && controller == null && identical(scrollDirection, Axis.vertical)) ? const AlwaysScrollableScrollPhysics() : null),
super(key: key);