Unverified Commit 6c0c6d30 authored by Pedro Massango's avatar Pedro Massango Committed by GitHub

Expose padEnds on PageView widget (#78558)

parent 14759dc5
...@@ -637,6 +637,7 @@ class PageView extends StatefulWidget { ...@@ -637,6 +637,7 @@ class PageView extends StatefulWidget {
this.restorationId, this.restorationId,
this.clipBehavior = Clip.hardEdge, this.clipBehavior = Clip.hardEdge,
this.scrollBehavior, this.scrollBehavior,
this.padEnds = true,
}) : assert(allowImplicitScrolling != null), }) : assert(allowImplicitScrolling != null),
assert(clipBehavior != null), assert(clipBehavior != null),
controller = controller ?? _defaultPageController, controller = controller ?? _defaultPageController,
...@@ -676,6 +677,7 @@ class PageView extends StatefulWidget { ...@@ -676,6 +677,7 @@ class PageView extends StatefulWidget {
this.restorationId, this.restorationId,
this.clipBehavior = Clip.hardEdge, this.clipBehavior = Clip.hardEdge,
this.scrollBehavior, this.scrollBehavior,
this.padEnds = true,
}) : assert(allowImplicitScrolling != null), }) : assert(allowImplicitScrolling != null),
assert(clipBehavior != null), assert(clipBehavior != null),
controller = controller ?? _defaultPageController, controller = controller ?? _defaultPageController,
...@@ -780,6 +782,7 @@ class PageView extends StatefulWidget { ...@@ -780,6 +782,7 @@ class PageView extends StatefulWidget {
this.restorationId, this.restorationId,
this.clipBehavior = Clip.hardEdge, this.clipBehavior = Clip.hardEdge,
this.scrollBehavior, this.scrollBehavior,
this.padEnds = true,
}) : assert(childrenDelegate != null), }) : assert(childrenDelegate != null),
assert(allowImplicitScrolling != null), assert(allowImplicitScrolling != null),
assert(clipBehavior != null), assert(clipBehavior != null),
...@@ -841,6 +844,10 @@ class PageView extends StatefulWidget { ...@@ -841,6 +844,10 @@ class PageView extends StatefulWidget {
final ScrollPhysics? physics; final ScrollPhysics? physics;
/// Set to false to disable page snapping, useful for custom scroll behavior. /// Set to false to disable page snapping, useful for custom scroll behavior.
///
/// If the [padEnds] is false and [PageController.viewportFraction] < 1.0,
/// the page will snap to the beginning of the viewport; otherwise, the page
/// will snap to the center of the viewport.
final bool pageSnapping; final bool pageSnapping;
/// Called whenever the page in the center of the viewport changes. /// Called whenever the page in the center of the viewport changes.
...@@ -873,6 +880,17 @@ class PageView extends StatefulWidget { ...@@ -873,6 +880,17 @@ class PageView extends StatefulWidget {
/// modified by default to not apply a [Scrollbar]. /// modified by default to not apply a [Scrollbar].
final ScrollBehavior? scrollBehavior; final ScrollBehavior? scrollBehavior;
/// Whether to add padding to both ends of the list.
///
/// If this is set to true and [PageController.viewportFraction] < 1.0, padding will be added
/// such that the first and last child slivers will be in the center of
/// the viewport when scrolled all the way to the start or end, respectively.
///
/// If [PageController.viewportFraction] >= 1.0, this property has no effect.
///
/// This property defaults to true and must not be null.
final bool padEnds;
@override @override
_PageViewState createState() => _PageViewState(); _PageViewState createState() => _PageViewState();
} }
...@@ -942,6 +960,7 @@ class _PageViewState extends State<PageView> { ...@@ -942,6 +960,7 @@ class _PageViewState extends State<PageView> {
SliverFillViewport( SliverFillViewport(
viewportFraction: widget.controller.viewportFraction, viewportFraction: widget.controller.viewportFraction,
delegate: widget.childrenDelegate, delegate: widget.childrenDelegate,
padEnds: widget.padEnds,
), ),
], ],
); );
......
...@@ -985,4 +985,29 @@ void main() { ...@@ -985,4 +985,29 @@ void main() {
renderObject.paint(context, Offset.zero); renderObject.paint(context, Offset.zero);
expect(context.clipBehavior, equals(Clip.antiAlias)); expect(context.clipBehavior, equals(Clip.antiAlias));
}); });
testWidgets('PageView.padEnds tests', (WidgetTester tester) async {
Finder viewportFinder() => find.byType(SliverFillViewport, skipOffstage: false);
// PageView() defaults to true.
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: PageView(
children: const <Widget>[],
),
));
expect(tester.widget<SliverFillViewport>(viewportFinder()).padEnds, true);
// PageView(padEnds: false) is propagated properly.
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: PageView(
padEnds: false,
children: const <Widget>[],
),
));
expect(tester.widget<SliverFillViewport>(viewportFinder()).padEnds, false);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment