简体   繁体   中英

Flutter using StreamingSharedPreferences in MultiProvider

this is simple of implementation for StreamingSharedPreferences using Provider

Future<void> main() async {
  final preferences = await StreamingSharedPreferences.instance;
  final settings = MyAppSettings(preferences);

  runApp(
    Provider<MyAppSettings>.value(value: settings, child: MyApp()),
  );
}

as i have another multiple Provider in application such as:

runApp(
  MultiProvider(providers: [
    Provider(builder: (_) => database.userTableDao),
    Provider(builder: (_) => database.postsTableDao),
    Provider(builder: (_) => database.postsTableDao),
    Provider(
      builder: (_) => ApiService.create(),
      dispose: (_, ApiService) => service.client.dispose(),
    )
  ], child: OKToast(child: MyHomePage())),
);

i'm not sure how can make StreamingSharedPreferences provider inside them, for example:

MultiProvider(providers: [
  ...
  Provider<ApplicationSettings>.value(value: settings),
  ...
], child: OKToast(child: MyHomePage())),

in this code i used instance of StreamingSharedPreferences.instance into main function and after that i added inside MultiProvider , for example:

final settings = ApplicationSettings( await StreamingSharedPreferences.instance );

MultiProvider(providers: [
  ...
  Provider( builder: (_) => settings ),
  ...
], child: OKToast(child: MyHomePage())),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM