该multi_image_picker: 2.4.11插件返回一个List<Asset>,每个Asset都有一个imageData属性是ByteData。
如何在 Flutter 中显示这些?
该multi_image_picker: 2.4.11插件返回一个List<Asset>,每个Asset都有一个imageData属性是ByteData。
如何在 Flutter 中显示这些?
您可以使用Image.memory构造函数。
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());
},
);
这是将转换 Asset -> Image 的函数
Future<Image> assetThumbToImage(Asset asset) async {
final ByteData byteData = await asset.getByteData();
final Image image = Image.memory(byteData.buffer.asUint8List());
return image;
}