routeSettings从Navigator到MaterialApp的颤振

问题描述 投票:0回答:1

有没有办法从Navigator类(超级...超级孩子)访问MaterialApp?

child: Navigator(
              onGenerateRoute: (RouteSettings settings){
                print('settings ${settings.name}');
                if(settings.name == '/'){
                  return MaterialPageRoute(
                      builder: (_) => _page(index),
                      settings: settings
                  );
                }
                else if(settings.name == '/blog_details'){
                  return CustomRoute<bool>(
                    builder: (BuildContext context) => BlogDetailsPage(widget.model)
                  );
                }
              },
            ),

从上面的代码到下面

child: MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: getAdaptiveThemeData(context),
          routes: { /// some routes///}
          onGenerateRoute: (RouteSettings settings){
            if(settings.name == '/blog_details'){
              return CustomRoute<bool>(
                builder: (BuildContext context) => BlogDetailsPage(_model)
              );
            }
          },
routes flutter navigator
1个回答
2
投票

您可以使用rootNavigator: true访问MaterialApp导航器,

FlatButton(
   child: Text('Push App Route'),
   onPressed: () {
     Navigator.of(context, rootNavigator: true)
         .pushNamed('/blog_details');
   },
)
© www.soinside.com 2019 - 2024. All rights reserved.