I’m getting an error in dart when I use the map function as iterable.
Future _addPostMedia() {
debugLog('Adding post media');
return Future.wait(_data.remainingCompressedMediaToUpload
.map(_uploadPostMediaItem as Function(File e)) as Iterable<Future>
.toList());}
Above I’m getting an error Expected to find ) just before the
.toList()
This was the original code which wasn’t working and VSCode recommend some fixes :
Future _compressPostMedia() {
debugLog(‘Compressing post media’);
return Future.wait(
_data.remainingMediaToCompress.map(_compressPostMediaItem)
.toList());}
2
Answers
Based on discussions with @Cstark, the following steps is what made the error disappear:
Attempted:
Vscode suggested a cast as a quick fix and the following is the final code:
Each level of casting needs to wrapped in its set of parenthesis, so you were missing a set wrapping the as Iterable.