My function looks like this:
Stream<QuerySnapshot> getAllLists() {
late String temp = "name";
getUserSortMethod().then((value) => {
temp = value.toString(),
// temp is now "prio"
});
return firestore
.collection('lists')
.where('editors', arrayContains: currentUser.email)
.orderBy(temp, descending: false)
.snapshots();
}
I need to wait for the result of getUserSortMethod() to use it in return. How can I use return and before that wait for result of getUserSortMethod function?
Tried to change main function to async return to
Future<Stream<QuerySnapshot<Object?>>> but get not working.
2
Answers
this works very well:
}
You are using async method but the method declaration doesn’t mention as async. In your sample code you don’t have
await
due to that firestore order will be done by name always. Because before completing the async operation it will return the snapshot.Otherwise run the
getUserSortMethod
async function then pass the result togetAllList
Function.