Flutter - Dart : wait a forEach ends

后端 未结 3 1963

I try to modify a string using data in each node I retrieve from Firebase database, and then to write a file with the modifed string (called \"content\").

He

3条回答
  •  悲哀的现实
    2021-01-06 18:24

    Have you tried:

    File file = await cacheManager.getFile(signedurl);
    content = content.replaceAll('test', file.path);
    

    instead of:

    cacheManager.getFile(signedurl).then((file){ ...});
    

    EDIT:

    Here's a fuller example trying to replicate what you have. I use a for loop instead of the forEach() method:

    void main () async {
      List str = await getFuture();
      print(str);
      var foo;
    
      for (var s in str) {
        var b = await Future(() => s);
        foo = b;
      }
    
      print('finish $foo');
    }
    
    getFuture() => Future(() => ['1', '2']); 
    

提交回复
热议问题