DART - how to combine two different Future based queries?

Viewed 22

I have a Flutter form that will require data from two different sources, i.e.

class DataForForm {
   MasterData master;
   List<Transaction> transactions;
}

One query will bring back 'master data', and a second query will bring back 'transaction data'.

How can I build a 'Future' call that will wait for both queries to execute, and for the results to be returned in the aggregated 'DataForForm' class?

1 Answers

Try something like this:

Future<DataForForm> getData(...) async {
  MasterData masterData = await getMasterData(...);
  List<Transaction> transactions = await getTransactions(...);
  return DataForm(master: masterData, transactions: transactions);
}
Related