Unverified Commit 01c1e8e5 authored by chunhtai's avatar chunhtai Committed by GitHub

Allows pushing page based route as pageless route (#114362)

* Allows pushing page based route as pageless route

* update
parent 22e1ac76
......@@ -180,6 +180,26 @@ void main() {
expect('$exception', startsWith('Navigator operation requested with a context'));
});
testWidgets('Navigator can push Route created through page class as Pageless route', (WidgetTester tester) async {
final GlobalKey<NavigatorState> nav = GlobalKey<NavigatorState>();
await tester.pumpWidget(
MaterialApp(
navigatorKey: nav,
home: const Scaffold(
body: Text('home'),
)
)
);
const MaterialPage<void> page = MaterialPage<void>(child: Text('page'));
nav.currentState!.push<void>(page.createRoute(nav.currentContext!));
await tester.pumpAndSettle();
expect(find.text('page'), findsOneWidget);
nav.currentState!.pop();
await tester.pumpAndSettle();
expect(find.text('home'), findsOneWidget);
});
testWidgets('Zero transition page-based route correctly notifies observers when it is popped', (WidgetTester tester) async {
final List<Page<void>> pages = <Page<void>>[
const ZeroTransitionPage(name: 'Page 1'),
......@@ -2758,62 +2778,6 @@ void main() {
);
});
Widget buildFrame(String action) {
const TestPage myPage = TestPage(key: ValueKey<String>('1'), name:'initial');
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
'/' : (BuildContext context) => OnTapPage(
id: action,
onTap: () {
if (action == 'push') {
Navigator.of(context).push(myPage.createRoute(context));
} else if (action == 'pushReplacement') {
Navigator.of(context).pushReplacement(myPage.createRoute(context));
} else if (action == 'pushAndRemoveUntil') {
Navigator.of(context).pushAndRemoveUntil(myPage.createRoute(context), (_) => true);
}
},
),
};
return MaterialApp(routes: routes);
}
void checkException(WidgetTester tester) {
final dynamic exception = tester.takeException();
expect(exception, isFlutterError);
final FlutterError error = exception as FlutterError;
expect(
error.toStringDeep(),
equalsIgnoringHashCodes(
'FlutterError\n'
' A page-based route should not be added using the imperative api.\n'
' Provide a new list with the corresponding Page to Navigator.pages\n'
' instead.\n',
),
);
}
testWidgets('throw if add page-based route using the imperative api - push', (WidgetTester tester) async {
await tester.pumpWidget(buildFrame('push'));
await tester.tap(find.text('push'));
await tester.pumpAndSettle();
checkException(tester);
});
testWidgets('throw if add page-based route using the imperative api - pushReplacement', (WidgetTester tester) async {
await tester.pumpWidget(buildFrame('pushReplacement'));
await tester.tap(find.text('pushReplacement'));
await tester.pumpAndSettle();
checkException(tester);
});
testWidgets('throw if add page-based route using the imperative api - pushAndRemoveUntil', (WidgetTester tester) async {
await tester.pumpWidget(buildFrame('pushAndRemoveUntil'));
await tester.tap(find.text('pushAndRemoveUntil'));
await tester.pumpAndSettle();
checkException(tester);
});
testWidgets('throw if page list is empty', (WidgetTester tester) async {
final List<TestPage> myPages = <TestPage>[];
final FlutterExceptionHandler? originalOnError = FlutterError.onError;
......
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