EmJeiEn
EmJeiEn

Reputation: 1443

Flutter: Value of List<File> can't be assigned to a variable of type List<Widget>

I'm trying to map selected images so that I can display them in the build.

I have:

 // declared earlier
List<File> _images;

List<Widget> image = _images
      if (_images != null) {
      _images.map((c) => new Image.file(c)
      ).toList();

Which is giving me the following error:

'List<File>' can't be assigned to a variable of type 'List<Widget>'.

I understand the error, File cannot be assigned to Widget, however I have no idea how to work around it?

Upvotes: 1

Views: 1220

Answers (1)

Richard Heap
Richard Heap

Reputation: 51741

The problem seems to be here List<Widget> image = _images.

Try

List<Widget> imageWidgets = _images.map<Image>((c) => new Image.file(c)).toList();

Upvotes: 1

Related Questions