I have a stream provider that should return userData of the current logged in user. It should take information of user whose email is equal to current user.email.I guess the stream provider load data before the email of the current user is saved b'se it load information of all users `. So how should I make stream provider to wait until the email of the current user is saved . The function that load current user.
Future<void>loadLoggedUser() async{
FirebaseAuth.instance
.userChanges()
.listen((User? user) {
if (user == null) {
print('User is currently signed out!');
} else {
email=user.email;
userid=user.uid;
print('User is signed in!');
}
});
notifyListeners();
}
Stream provider for userData
Stream<List<UserData>> get UserList {
return _db.collection('users').where('email', isEqualTo: email)
.snapshots()
.map((snapshot) =>
snapshot.docs
.map((document) =>
UserData.fromJson(document.data())).toList()
);
}
Any help will be appreciated