[英]Understanding Multiprovider with Flutter
我正在尋找如何在 flutter 上獲得多個 stream 提供商。我所擁有的是這個
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
runApp(const GroupVestmentApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return StreamProvider<UserInfo?>.value(
value: AuthService().userinfo,
initialData: null,
child: MaterialApp(
home: SplashScreen(),
),
);
}
}
我想要的是像
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
runApp(const GroupVestmentApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MultiProvider([
child:StreamProvider<UserInfo?>.value(
value: AuthService().userinfo,
initialData: null,
child: MaterialApp(
home: SplashScreen(),
),
child:StreamProvider<NewInfo?>.value(
value: AuthService().Newinfo,
initialData: null,
child: MaterialApp(
home: SplashScreen(),
)],
);
}
}
基本上我想要兩個不同的 stream 供應商。 一個用於特定的一組用戶,另一個用於另一組用戶。 其中每一個都指向不同的注冊方法。 有人知道如何讓它工作嗎? 提前致謝
MultiProvider
只是一種注入多個提供者的方法。
MultiProvider(
providers: [
Provider<Something>(create: (_) => Something()),
Provider<SomethingElse>(create: (_) => SomethingElse()),
Provider<AnotherThing>(create: (_) => AnotherThing()),
],
child: MyWidget(),
)
在MyWidget
中根據需求選擇需要的那個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.