Commit 0a85db29 authored by Iiro Krankka's avatar Iiro Krankka Committed by Adam Barth

Change PageController#nextPage & #previousPage methods to return Future when...

Change PageController#nextPage & #previousPage methods to return Future when the animation completes. (#12299)

* Changed PageController #nextPage & #previousPage to return a Future after completing.

* Removed false statement about returning a Future in PageController#jumpToPage

* Added tests to make sure nextPage & previousPage return Futures.

* Tested that the Futures returned by nextPage & previousPage actually resolve.

* Renaming *pageCalled to *pageCompleted, since that's what it's actually for.
parent c02850b4
......@@ -114,8 +114,8 @@ class PageController extends ScrollController {
/// The returned [Future] resolves when the animation completes.
///
/// The `duration` and `curve` arguments must not be null.
void nextPage({ @required Duration duration, @required Curve curve }) {
animateToPage(page.round() + 1, duration: duration, curve: curve);
Future<Null> nextPage({ @required Duration duration, @required Curve curve }) {
return animateToPage(page.round() + 1, duration: duration, curve: curve);
}
/// Animates the controlled [PageView] to the previous page.
......@@ -124,8 +124,8 @@ class PageController extends ScrollController {
/// The returned [Future] resolves when the animation completes.
///
/// The `duration` and `curve` arguments must not be null.
void previousPage({ @required Duration duration, @required Curve curve }) {
animateToPage(page.round() - 1, duration: duration, curve: curve);
Future<Null> previousPage({ @required Duration duration, @required Curve curve }) {
return animateToPage(page.round() - 1, duration: duration, curve: curve);
}
@override
......
......@@ -211,6 +211,38 @@ void main() {
expect(find.text('Arizona'), findsOneWidget);
});
testWidgets('PageController nextPage and previousPage return Futures that resolve', (WidgetTester tester) async {
final PageController controller = new PageController();
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
child: new PageView(
controller: controller,
children: kStates.map<Widget>((String state) => new Text(state)).toList(),
),
));
bool nextPageCompleted = false;
controller.nextPage(duration: const Duration(milliseconds: 150), curve: Curves.ease)
.then((_) => nextPageCompleted = true);
expect(nextPageCompleted, false);
await tester.pump(const Duration(milliseconds: 200));
expect(nextPageCompleted, false);
await tester.pump(const Duration(milliseconds: 200));
expect(nextPageCompleted, true);
bool previousPageCompleted = false;
controller.previousPage(duration: const Duration(milliseconds: 150), curve: Curves.ease)
.then((_) => previousPageCompleted = true);
expect(previousPageCompleted, false);
await tester.pump(const Duration(milliseconds: 200));
expect(previousPageCompleted, false);
await tester.pump(const Duration(milliseconds: 200));
expect(previousPageCompleted, true);
});
testWidgets('PageView in zero-size container', (WidgetTester tester) async {
await tester.pumpWidget(new Directionality(
textDirection: TextDirection.ltr,
......
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