listflutterdartsharedpreferencesuint8list

Flutter - How to put List<Uint8List> into shared preferences?


I have a list of Unit8List which stores data of multiple images. I want to share the list with other activities so that other activities can use the list to display the images. So how can i share using SharedPreferences? or is there any way that i can use to pass the list having Unit8List objects?


Solution

  • I believe the other answer as proposed by Christopher will give incorrect results for some binary values, at least on Android. The correct approach is to use a standard binary to printable string encoding. A common one is Base64.

    // convert to Base64
    var printableString = base64.encode(bytesIn);
    
    // and back
    var bytesOut = base64.decode(printableString);