简体   繁体   中英

A value of type 'List<Customer>' can't be assigned to a variable of type 'Future<List<Customer>>'

How to convert 'List' to 'Future<List>'. I need get two type ('List' & 'Future<List>' ) in different places

My api response

var data = jsonDecode(r.body);
  custList.add(new Customer(
      data[i]['CustomerID'],
      '${data[i]['ProfileImageUrl']}' + '${data[i]['ProfileImage']}',
      '${data[i]['CompanyName']}',
      data[i]['Email'],
      data[i]['RegisterNumber'],
      data[i]['PhoneNumber'],
      data[i]['BillingStreet'],
      data[i]['BillingCity'],
      data[i]['BillingZip'],
      data[i]['MasterCountryName'],
      data[i]['MasterStateName'],
      data[i]['Type'],
      new customeraddress(data[i]['BillingStreet'],
          data[i]['BillingCity'], data[i]['BillingZip']),
    status,
      data[i]['CustomerTaxExemptType'],
    data[i]['MasterCountryID'],
    data[i]['MasterStateID'],
  ));

How to convert 'List' to 'Future<List>'.

If you are not entirely sure if you get a T or a Future<T> , you can use the FutureOr<T> ( documentation ) class.

To create a Future<T> from a value to satisfy some compiler syntax, you can use the named constructor Future.value ( documentation ).

For more information on Futures: What is a Future and how do I use it?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM