user11065582
user11065582

Reputation:

How to convert to List<int> to File?

I need to store image file to SQLite database using SQLite.

I used this method,

 var image = await ImagePicker.pickImage(source: imageSource);
    List<int> bytes = await image.readAsBytes(); 

https://stackoverflow.com/a/55258035/11065582

QUESTION 1 - what is the type when create table?(CREATE TABLE registerTable(image ?,) QUESTION 2 - how to convert to again File?

Upvotes: 7

Views: 10211

Answers (1)

jamesdlin
jamesdlin

Reputation: 89946

If you have a List<int> that represents a list of 8-bit bytes and want to write it to a file, you can simply use File.writeAsBytes. (It's the inverse of File.readAsBytes, which you're already using.)

await File(desiredDestinationPath).writeAsBytes(bytes);

All that said, why do you need to write to a File? If you already have the image data and want to show it, you can create a MemoryImage (or use Image.memory if you need an Image widget).

Upvotes: 6

Related Questions