Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I wrap the MaterialApp widget with the Provider?

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.

like image 967
Madusha Lakruwan Avatar asked Dec 18 '22 15:12

Madusha Lakruwan


1 Answers

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

like image 69
Rémi Rousselet Avatar answered Feb 03 '23 17:02

Rémi Rousselet