I am to listening firebase AuthStateChanges
stream and provide the stream with streamProvider
to change the view based on the stream value. And I did this:
class AuthService {
final FirebaseAuth _auth = FirebaseAuth.instance;
Stream get currentUser => _auth.authStateChanges();
}
final userStream = StreamProvider.autoDispose((ref) => AuthService().currentUser);
class AuthenticationWrapper extends ConsumerWidget {
@override
Widget build(BuildContext context, ScopedReader watch) {
final user = watch(userStream);
print('AutenticationWrapper build method got called');
return user.when(
data: (data) {
if (data?.uid == null) {
print('I am currently Logged out ??');
return LogInPage();
} else {
print('I am logged in user??');
return HomePage();
}
},
loading: () => CircularProgressIndicator(),
error: (e, s) => Text('Oops'),
);
}
}
I was expecting to have LogIn page to be rendered when the AsyncValue
of the streamProvider
gets changed. The above code didn't work as expected; in fact, it prints the message but it doesn't return the Widget it is supposed to return. However, when I hot restart the app it will render the correct Widget based on the stream value.
Why doesn't the build method re-render when this: final user = watch(userStream);
receives an update?
question from:
https://stackoverflow.com/questions/65830274/streamprovider-not-rebuilding-the-widget-tree-when-asyncvalue-updates 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…