Can I wrap the MaterialApp widget with the Provider?

六月ゝ 毕业季﹏ 提交于 2020-03-23 06:21:15

问题


I'm new to flutter and I'm trying to create an app with provider. I wrapped MaterialApp widget with the ChangeNotifierProvider and the app works and I can use the provider as it intended to do. I need to know is it okay to do so and will i face any problems?

Widget build(BuildContext context) {
    return ChangeNotifierProvider<BaseModel>(
        builder: (context) =>
            BaseModel(loading: false, title: "Title", isLoggedIn: false),
        child: MaterialApp(
            routes: <String, WidgetBuilder>{
                "/home": (BuildContext context) => Home(),
                "/signIn": (BuildContext context) => SignIn()
            },
            initialRoute: "/signIn",
            title: 'Flutter Demo',
            theme: ThemeData(
                // is not restarted.
                primarySwatch: Colors.blue,
            ),
            home: SignIn()),
    );

In all the sample codes they use Provider under "home" in MaterialApp widget. I used MaterialApp inside the provider.


回答1:


It is totally fine. There's no problem whatsoever.



来源:https://stackoverflow.com/questions/57691515/can-i-wrap-the-materialapp-widget-with-the-provider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!