基本上我想在应用程序启动时加载firebase远程配置参数并在创建商店时将其存储在应用程序状态中。
因此,每当我需要它时,我只需从商店中获取它并获取 remoteConfig 值。
class App extends StatelessWidget {
// Get firebase remote config and store it in appState
---> final store = createStore();
App();
@override
Widget build(BuildContext context) {
return new PersistorGate(
persistor: persistor,
loading: new LoadingScreen(),
builder: (context) => new StoreProvider<AppState>(
store: store,
child: new MaterialApp(
title: 'TestApp',
theme: defaultTargetPlatform == TargetPlatform.iOS
? kIOSTheme
: kDefaultTheme,
routes: getRoutes(context, store),
initialRoute: '/login',
)),
);
}
}
创建存储文件 -
Store<AppState> createStore() {
Store<AppState> store = new Store(
appReducer,
// store remote config in initial app state
initialState: new AppState(),
middleware: createMiddleware(),
);
persistor.load(store);
return store;
}