I have an asynchronous function in Flutter which communicates with Firestore. There's a server-function that runs, and my indication of the completion of the task a flag that I listen to using StreamSubscription. The StreamSubscription listening code is wrapped with a Future async function, yet I can't understand how do I return a Future from the function handler of StreamSubscription.
static Future<bool> listenToProcess(
String doc, Function func) {
StreamSubscription<DocumentSnapshot> stream = Firestore.instance.collection('requests').document(doc)
.snapshots().listen((data){
if (data.data["done"])
func(true);
print ("change " + data.data["done"].toString());
});
}
The function should wait for the stream to get a done=true future answer.