I have a Flutter app which uses Firebase-storage and google-signin. the steps I am trying to do is so simple:
1- Sign-in using Google (Done).
2- Get Current User Id (Done).
3- Use the User Id when construct the stream for the stream builder (the problem).
what I did so far is that I am using a Future to get the Current User Id,
then to inject the user Id inside the Where clause
.where('userId', isEqualTo: userId)
and this is what I end up with:
this is the part where I should create the stream:
// Get document's snapshots and return it as stream.
Future<Stream> getDataStreamSnapshots() async {
// Get current user.
final User user = await FirebaseAuth().currentUser();
String userId = user.uid;
Stream<QuerySnapshot> snapshots =
db
.collection(db)
.where("uid", isEqualTo: userId)
.snapshots();
try {
return snapshots;
} catch(e) {
print(e);
return null;
}
}
and this is the part where should I call and receive the stream,
...
children: <Widget>[
StreamBuilder<QuerySnapshot>(
stream: CALLING THE PREVIOUS FUNCTION,
builder: (BuildContext context,
AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
...
}
...
But this code does not work, because I am not able to get the value that should returned by the Future? any idea?
thanks a lot