Hi There i am using the Hydrated Bloc and saving the user auth status in the bloc like this.
@override
Map<String, dynamic>? toJson(AuthState state) {
if (state.status == AuthStatus.authenticated) {
HydratedBloc.storage.write('user', json);
return state.user?.toJson();
} else {
return {};
}
}
Now after logged in the user and saving the data i am navigating the user to the home screen. In the home screen i am trying to print the saved data something like this.
await HydratedBloc.storage.read('user');
But i am getting null
here.
This may be because hydrated bloc may have not written the data and i am fetching it in home screen.
But if thats the case then how can i wait to write the data ?
I have tried wrapping
HydratedBloc.storage.write('user', json)
in separate function and using
await
but that too doesn’t works ?
Let me know how can i solve this issue ?`