Trying to read a streamProvider inside initState, but failed. Enlight me please, what am I doing wrong here?
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
final userStream = context.read(userStreamProvider);
print('user : $userStream'); // user : AsyncValue<Null>.loading()
});
}
So far, what I found that context.read(userStreamProvider)
only works inside
build(BuildContext context)
method
Your code works. The problem is, you are not waiting for the user to be loaded.
What you want is probably:
By reading
userStreamProvider.last
, you will be able to wait for the user to be loaded. You can then use.then
orawait
like with all futures.