本文介绍了我可以使用提供程序包装MaterialApp小部件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是扑朔迷离的新手,我正在尝试使用提供程序创建一个应用程序.我用ChangeNotifierProvider包装了MaterialApp小部件,并且该应用程序可以运行,并且可以按预期使用提供程序.我需要知道是否可以这样做,我会遇到任何问题吗?
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()),
);
在所有示例代码中,他们在MaterialApp小部件的主页"下使用Provider.我在提供程序内部使用了MaterialApp.
In all the sample codes they use Provider under "home" in MaterialApp widget. I used MaterialApp inside the provider.
推荐答案
完全没问题.没问题.
It is totally fine. There's no problem whatsoever.
这篇关于我可以使用提供程序包装MaterialApp小部件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!