1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Can I wrap the MaterialApp widget with the Provider?

Discussão em 'Mobile' iniciado por Stack, Setembro 28, 2024 às 03:33.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página