Closed archie-sh closed 3 years ago
What you are doing is fine, but there are other options. You are assuming the store can't exist before some info in it is initialized, but that's not true. Some store.state.isInitialized
flag can indicate if the store is initialized or not.
Start by removing the FutureBuilder
, and your onGenerateRoute
should call your home-page widget, HomePageConnector
, which is a connector that checks the store.state.isInitialized
flag:
@override
Widget build(BuildContext context) {
return StoreConnector<AppState, _Vm>(
vm: () => _Factory(),
builder: (context, vm) {
if (vm.isInitialized) {
if (vm.isLoggedIn) return HomePage();
else return LoginPage();
}
else
return const Center(child: CircularProgressIndicator());
},
);
}
Hi, I need to load data from the backend and run business logic when the app starts. flutter_redux has a onInit method that gets the store passed as an argument, maybe a similar implementation can be added to async_redux.
My current workaround is to use FutureBuilder: