I need to navigate to a widget(screen) using named navigation from another widget(screen). This is the body of MyHomePage Widget
body: Navigator(
key: _navigatorKey,
initialRoute: '/',
onGenerateRoute: (RouteSettings settings) {
WidgetBuilder builder;
switch (settings.name) {
case '/':
builder = (BuildContext context) => UIHomePage();
break;
case '/cart':
builder = (BuildContext context) => UICartPage();
break;
case '/account':
builder = (BuildContext context) => UIAccountPage();
break;
default:
throw Exception('Invalid route: ${settings.name}');
}
return MaterialPageRoute(builder: builder, settings: settings, );
},
),
I can toggle these PageRoutes from the bottomNavigationBar with _navigatorKey.currentState.pushNamed(routeNames[tabItem]) where routeNames is a list of Strings ['/', '/cart', '/account']. This works fine.
Now, from UIAccountPage(), where I have a ListTile named 'Cart', I wish to navigate to the UICartPage on tapping that particular tile. I also have several other tiles that I wish to use to navigate to other widgets (screens).
To achieve this, do I have to expand the onGenerateRoute in MyHomePage to accommodate other routes or I have to create another custom Navigator somewhere? I am at odds. If somebody could guide with a simple illustration that would be awesome.
Thanks
Edit: Also I have no idea what setting does in Navigator and _navigatorKey is final _navigatorKey = GlobalKey<NavigatorState>()