bizz84 / nested-navigation-demo-flutter

Nested navigation with BottomNavigationBar
https://codewithandrea.com/
MIT License
622 stars 139 forks source link

How to get parent navigator in flutter not an ancestor? #20

Closed zoran888 closed 3 years ago

zoran888 commented 3 years ago

I am facing getting parent navigator in flutter and I am trying this approach.

In login screen, when authentication is successful, app navigates to Home screen which has bottom navigator. bottom navigator has 3 tabs and each tab has multiple screen as child. To keep navigator independent between 3 tabs, I defined navigatorKeys for each tab.

And to navigate to detail screen of each tab, I am using this code snippet.

void _push(BuildContext context, {required String routeName}) {
    final routeBuilders = _routeBuilders(context);

    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => routeBuilders[routeName]!(context),
      ),
    );
}

The problem is navigated screen overlaps bottom tab but my intention was to keep bottom navigation bar. I think Navigator gets the ancestor navigator which is parent of both login screen and home screen and that's why child screen of tab navigator overlays bottom navigation bar. I am not a veteran at Flutter so have no idea how to handle this at the moment. It would be appreciated if someone could help me with this.

Thank you!

zoran888 commented 3 years ago

@bizz84 Can you please let me know how to handle this? Thanks.

image