我有此更改通知者:
runApp(
ChangeNotifierProvider<AuthService>(
child: MyApp(),
create: (BuildContext context) {
return AuthService();
},
),
);
但是我还需要添加一个新的:
ChangeNotifierProvider(
create: (_) => ThemeProvider(isLightTheme: true),
child: MyApp(),
);
由于runapp似乎不允许这样做,我该怎么办?
答案 0 :(得分:1)
您可以嵌套提供程序或使用MultiProvider
:
ChangeNotifierProvider(
create: (_) => AuthService(),
child: ChangeNotifierProvider(
create: (_) => ThemeProvider(),
child: MyApp(),
),
)
或:
MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => AuthService()),
ChangeNotifierProvider(create: (_) => ThemeProvider()),
],
child: MyApp(),
)