Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i wrap my Dart result value with a Future?

Tags:

dart

I have a function which returns a list of emails, but in side of it, it builds the list and tries to return it.

How do i return the list wrapped in a future?

Future<List<Email>> getEmails(){
  List<Email> emailList = new List<Email>();
    //loop to build a set of dummy data
  return emailList;
}
like image 537
Fallenreaper Avatar asked Jan 18 '16 21:01

Fallenreaper


1 Answers

Several options:

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

  • you can annotate the function body with the async keyword:

Future<List<Email>> getEmails() async {
  List<Email> emailList = new List<Email>();
    //loop to build a set of dummy data
  return emailList;
}
like image 98
Alexandre Ardhuin Avatar answered Nov 15 '22 20:11

Alexandre Ardhuin