Reputation: 134
I'm using flutter with the pdf
plugin to generate a PDF document where I need to display a grid of images. The images are stored in a List<File>
.
Here's what I've tried. Keep in mind that all these widgets are from the pdf
package and not from material
.
GridView(
crossAxisCount: 5,
childAspectRatio: 1,
children: door.images.map((image) {
return Container(
child: Image(MemoryImage(?????), fit: BoxFit.cover),
);
}).toList(),
),
Note: door.images
is the List<File>
How do I convert the File image
(from the List<File>
) to the Uint8List bytes
needed for the MemoryImage
widgets?
Upvotes: 3
Views: 836
Reputation: 3
Please Create List<MemoryImage>
instead of List<File>
MemoryImage(
(await rootBundle.load('assets/images/whatsapp.png')).buffer.asUint8List(),
)
Upvotes: 0
Reputation: 1193
Convert your File to imagebytes.
final List<int> _imageBytes = await image.readAsBytes();
And then convert the imagebytes to your Uint8List.
final String _uint8List = base64Encode(_imageBytes);
Upvotes: 1