How to transfer the meaning of the Dart result to the future?

I have a function that returns a list of letters, but aside from it, it builds a list and tries to return it.

How can I return a list wrapped in the future?

Future<List<Email>> getEmails(){
  List<Email> emailList = new List<Email>();
    //loop to build a set of dummy data
  return emailList;
}
+4
source share
1 answer

Several parameters:

  • you can wrap the return value with new Future<List<Email>>.value(emailList);

  • you can annotate function body with keyword async:

Future<List<Email>> getEmails() async {
  List<Email> emailList = new List<Email>();
    //loop to build a set of dummy data
  return emailList;
}
+4
source

Source: https://habr.com/ru/post/1624863/


All Articles