是否可以使用脚手架和导航器?

时间:2020-05-26 20:06:18

标签: flutter dart

我需要使用脚手架,以便可以使用抽屉,但也需要使用导航器。到目前为止,这是我的全部内容,但是不确定如何在本地使用Scaffold?

void main() {
  setupLocator();
  runApp(new App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle.dark.copyWith(statusBarColor: Colors.transparent),
    );

    return LifeCycleManager(
        child: MaterialApp(
      builder: (context, widget) => SafeArea(
        child: Navigator(
          onGenerateRoute: Router.generateRoute,
          initialRoute: routes.RegisterRoute,
        ),
        top: true,
        bottom: true,
        left: false,
        right: false,
        // title: 'Register',
        // home: OnBoardingPage(), <-- probably where my scaffold should go but using initialRoute above?
      ),
    ));
  }
}

1 个答案:

答案 0 :(得分:3)

我可能有解决方案,但我不知道它会有多大帮助。

我喜欢打电话

void main() async {
//staff I want to do before app starts
//maybe I want to call something saved in phone memory or idk,mabye this
 SystemChrome.setSystemUIOverlayStyle(
      SystemUiOverlayStyle.dark.copyWith(statusBarColor: Colors.transparent),
    );

  Widget _defaultHome = new IntroScreen();
//I recommend this because you can make some tests before

runApp(new MaterialApp(
 home: defaultHome,//or call direct the page you want
    routes: <String, WidgetBuilder>{
//routes
  '/login': (BuildContext context) => new MyLoginPage(),//example
    },
  ));
}
}

您将可以在需要时致电:

Navigator.pushNamed(context,'/login');