Search code examples
flutterflutter-pluginflutter-image

How to load Image widgets from ByteData in Flutter


The multi_image_picker: 2.4.11 plugin returns a List<Asset>, each Asset having an imageData property that is a ByteData.

How can I show these in Flutter?


Solution

  • You can use the Image.memory constructor.

    List<Asset> assets = ...; // use multi_image_picker to get the assets
    
    return ListView.builder(
      padding: EdgeInsets.all(8.0),
      itemExtent: assets.length,
      itemBuilder: (BuildContext context, int index) {
        return Image.memory(assets[index].imageData.buffer.asUint8List());
      },
    );