skip to Main Content
List<Image> convertToImgList(Future<List<Image>> listimg) {
  var li = listimg.asStream();
  Future<int> future = listimg.asStream().length;
  return images;
}

Hi,
I want to convert Future List Image to List Image in flutter.
Anyone knows how it can be done?

2

Answers


  1. It is future so you much wait for it by await:

    void main () async {
      Future<List<Image>> listimg = _yourFutureData();
      List<Image> imageList = await listimg;
    }
    
    Login or Signup to reply.
  2. Convert from Future<List<Image>>

    final Future<List<Image>> listFutureImages = Future<List<Image>>();
    final List<Image> listImages = await listFutureImages;
    

    Convert from List<Future<Image>>

    final Future<List<Image>> listFutureImages = List<Future<Image>>();
    final List<Image> listImages = await  Future.wait(
       listFutureImages.map(
          (e) async => await e,
       ),
    );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search