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.
This commit is contained in:
parent
c02850b4dc
commit
0a85db2958
@ -114,8 +114,8 @@ class PageController extends ScrollController {
|
|||||||
/// The returned [Future] resolves when the animation completes.
|
/// The returned [Future] resolves when the animation completes.
|
||||||
///
|
///
|
||||||
/// The `duration` and `curve` arguments must not be null.
|
/// The `duration` and `curve` arguments must not be null.
|
||||||
void nextPage({ @required Duration duration, @required Curve curve }) {
|
Future<Null> nextPage({ @required Duration duration, @required Curve curve }) {
|
||||||
animateToPage(page.round() + 1, duration: duration, curve: curve);
|
return animateToPage(page.round() + 1, duration: duration, curve: curve);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Animates the controlled [PageView] to the previous page.
|
/// 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 returned [Future] resolves when the animation completes.
|
||||||
///
|
///
|
||||||
/// The `duration` and `curve` arguments must not be null.
|
/// The `duration` and `curve` arguments must not be null.
|
||||||
void previousPage({ @required Duration duration, @required Curve curve }) {
|
Future<Null> previousPage({ @required Duration duration, @required Curve curve }) {
|
||||||
animateToPage(page.round() - 1, duration: duration, curve: curve);
|
return animateToPage(page.round() - 1, duration: duration, curve: curve);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -211,6 +211,38 @@ void main() {
|
|||||||
expect(find.text('Arizona'), findsOneWidget);
|
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 {
|
testWidgets('PageView in zero-size container', (WidgetTester tester) async {
|
||||||
await tester.pumpWidget(new Directionality(
|
await tester.pumpWidget(new Directionality(
|
||||||
textDirection: TextDirection.ltr,
|
textDirection: TextDirection.ltr,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user