- I have a document with the totalUnpaid amount of a user.
- I'm listening to this document with a StreamBuilder.
- The stream is a function that returns Stream.
When I register a new user, I create the totalUnpaid document with a field of int 0. Then immediately after, I navigate to a home page that shows the current totalUnpaid amount. Previously, I've hard-coded the current user as a string. Now that I've implemented Firebase authentication, I want the home page to show the totalUnpaid of the new user.
Previously, my stream was this:
static Stream<DocumentSnapshot> getTotalUnpaid(String currentUser) {
final doc = Firestore.instance.collection(currentUser).document('totalUnpaid');
return doc.snapshots();
}
Now I've created this method to get my current user:
static Future<FirebaseUser> getCurrentUser() async {
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
return user;
}
How can I consume this Future inside my stream? I will have to use an await, which will require the function to be async which will require the Stream to become a future which will require my StreamBuilder to become a FutureBuilder.
This won't be ideal, since the totalUnpaid needs to update every time the user adds an item.