buildViewport method
- BuildContext context,
- ViewportOffset offset,
- AxisDirection axisDirection,
- List<
Widget> slivers,
Build the viewport.
Subclasses may override this method to change how the viewport is built. The default implementation uses a ShrinkWrappingViewport if shrinkWrap is true, and a regular Viewport otherwise.
The offset
argument is the value obtained from
Scrollable.viewportBuilder.
The axisDirection
argument is the value obtained from getDirection,
which by default uses scrollDirection and reverse.
The slivers
argument is the value obtained from buildSlivers.
Implementation
@protected
Widget buildViewport(
BuildContext context,
ViewportOffset offset,
AxisDirection axisDirection,
List<Widget> slivers,
) {
assert(() {
switch (axisDirection) {
case AxisDirection.up:
case AxisDirection.down:
return debugCheckHasDirectionality(
context,
why: 'to determine the cross-axis direction of the scroll view',
hint: 'Vertical scroll views create Viewport widgets that try to determine their cross axis direction '
'from the ambient Directionality.',
);
case AxisDirection.left:
case AxisDirection.right:
return true;
}
}());
if (shrinkWrap) {
return ShrinkWrappingViewport(
axisDirection: axisDirection,
offset: offset,
slivers: slivers,
clipBehavior: clipBehavior,
);
}
return Viewport(
axisDirection: axisDirection,
offset: offset,
slivers: slivers,
cacheExtent: cacheExtent,
center: center,
anchor: anchor,
clipBehavior: clipBehavior,
);
}