0
DocumentSnapshot snapshot1 = await FirebaseFirestore.instance
        .collection('users')
        .doc('a')
        .get();

DocumentSnapshot snapshot2 = await FirebaseFirestore.instance
        .collection('users')
        .doc('b')    
        .get();

If implemented in this way, the query statements of snapshot2 cannot be executed until all data of snapshot1 is received. It doesn't happen at the same time.

I want to call a function only when both awaits are finished.

dontknowhy
  • 2,480
  • 2
  • 23
  • 67

1 Answers1

1

Try Future.wait([List<Future>]). Proper usage is described at this answer.

David Sedlář
  • 706
  • 5
  • 15
  • after Future.wait([List]). how to use return value? if it is not FutureBuilder? – dontknowhy Jan 29 '21 at 12:49
  • 1
    If you await entire command like 'final results = await Future.wait([future1, future2])' you'll get List of results for each future. You can acces them like 'final resultFromFirst = results[0]' and so on. You can use this data however you want. – David Sedlář Jan 29 '21 at 12:51