Skip to content

Instantly share code, notes, and snippets.

@shalaby
Created December 10, 2019 10:43
Show Gist options
  • Save shalaby/1c146491fa4090c2cb81c186ec87491f to your computer and use it in GitHub Desktop.
Save shalaby/1c146491fa4090c2cb81c186ec87491f to your computer and use it in GitHub Desktop.
Creating another Navigator right inside of MaterialApp
Creating another Navigator right inside of MaterialApp - some kind of a second 'sub-root' navigator.
Now you will be able to choose between 2 layers of Navigator depending on your needs.
Navigator.of(context, rootNavigator: true) will return the top-level Navigator - use it for your Flushbar or any other modal popups that you want to keep persistent above all screens.
Navigator.of(context), where rootNavigator is false by default. Use it to get the 'sub-root' Navigator to display new screens / pages.
e.g. placing another Navigator right in the MaterialApp.
MaterialApp(
home: Navigator( // 'sub-root' navigator. Second in the hierarchy.
onGenerateRoute: (_) => MaterialPageRoute(
builder: (_) => FirstScreen(),
settings: RouteSettings(isInitialRoute: true),
),
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment