If you want to get a list of users,
just set Firestore.instance.collection("users").snapshots()
to the Futurebuilder's future:
But, how can I use userDataRef()
to get user's data based on userId using FutureBuilder?
Future<Stream<DocumentSnapshot>> userDataRef() async {
final FirebaseUser user = await auth.currentUser();
return Firestore.instance
.collection("users")
.document(user.uid).snapshots();
}
This is my FutureBuilder. trying to display users favorite foods.
FutureBuilder(
future: Database.shared.userDataRef(),
builder: (BuildContext context, snapshot) {
if (!snapshot.hasData) {
return Text("Error");
}
final doc = snapshot.data.documents;
final List favoriteFoods = doc["favorite_foods"];
return Text(favoriteFoods.toString());
},
Any advice will be appreciated.
Thanks.
You can use nested
FutureBuilder
's like this :