I have a memory image stored in Sqllite converted to String with the toString() method, I want to convert it to Unit8List to display it inside a MemoryImage widget
Uint8List class Null safety. A fixed-length list of 8-bit unsigned integers. For long lists, this implementation can be considerably more space- and time-efficient than the default List implementation.
Using MemoryImage Constructor It contains the bytes to be decoded into an image. The other, which is optional, is a double named scale , used the scale the size of the image. Therefore, you need to have the image data as Unit8List bytes. To convert an image into Unit8List , you can make use of Flutter's AssetBundle .
codeUnits
gets you a List<int>
Uint8List.fromList(...)
converts List<int>
to Uint8List
String.fromCharCodes(...)
converts List<int>
or Uint8List
to String
List<int> list = 'xxx'.codeUnits;
Uint8List bytes = Uint8List.fromList(list);
String string = String.fromCharCodes(bytes);
Use utf8.encode(myString)
to convert String to bytes or List<int>
,
And then convert it back using utf8.decode(bytes)
String source = 'Błonie';
List<int> list = utf8.encode(source);
Uint8List bytes = Uint8List.fromList(list);
String outcome = utf8.decode(bytes);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With