Hello i get error "then", when i add this code for fetching posts from firebase, not sure how to fix this..
void initState() {
super.initState();
FirebaseAuth.instance.currentUser.then((value) {
print("got user");
FirebaseFirestore.instance
.collection('/profile')
.doc(value.uid)
.get()
.then((uservalue) {
savedImages = UserModel.fromJson(uservalue.data()).savedImagesPosts;
savedText = UserModel.fromJson(uservalue.data()).savedTextPosts;
setState(() {});
print("got list");
print(savedImages);
});
});
}
CodePudding user response:
FirebaseAuth.instance.currentUser
is a getter that will return the user or null if there is no current user. You can't call then on it.
If what you want to do is run some code when a user logs in:
FirebaseAuth.instance.userChanges().listen((user) {
if (user != null) {
// do something.
}
});