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?
Flutter - How to put List<Uint8List> into shared preferences?
1.9k Views Asked by KUNAL HIRANI At
2
There are 2 best solutions below
5
Christopher Moore
On
You can use the following code to essentially "convert" your Uint8List to a String, which can then be easily stored in SharedPreferences with the setString method of the SharePreferences class:
String s = String.fromCharCodes(inputAsUint8List);
and converting back
var outputAsUint8List = Uint8List.fromList(s.codeUnits);
Credit to Günter Zöchbauer for the String conversion.
Alternatively(as Richard Heap suggested), you could base64 encode your data with
String s = base64.encode(inputAsList);
in the dart:convert library for potentially greater safety, though this will increase the amount of space you will use to store the string.
Related Questions in LIST
- Difference between list() and dict() with generators
- python how to write list of lists to file
- SML - Find same elements in a string
- How to divide list item by list item from another list using Python?
- How to get a certain element in a list of lists?
- How to read in numbers from n lines into a Scala list?
- Create a list of sequential monthly dates in PHP given initial date and quantity
- Python elegant way to sort numerically named directories
- sorting all data on multiple pages by clicking on its header
- List item keeps same memory address following sort/copy
- How to convert Hibernate List to String?
- using a for loop to compare lists
- How to keep track of word count in text file
- Running multiprocessing on two different functions in Python 2.7
- How do you fuse string items from two lists into new elements of a new list?
Related Questions in FLUTTER
- Bug report: Issue building flutter on a mac
- Is there a way to control where a Text widget overflow occurs (how many lines)?
- How to save to local storage using Flutter?
- How do you use a TextPainter to draw text?
- Passing command line arguments to a flutter app
- IconButton calling setState during onPressed shows no ripple effect
- What would be a good way for a widget to take 1/3 of the screen?
- How can I test a TextPainter?
- How can I inherit a StatefulWidget's State?
- Life cycle in flutter
- Preloading local image assets in Flutter
- Flutter app not able to run in IntelliJ
- Is there a way to call specific code right before the app is killed or moves to the background?
- How can I layout widgets based on the size of the parent?
- Multi-line TextField in Flutter
Related Questions in DART
- How to set a component published attribute
- using dart route package url got error 404
- Using Document Discovery service on a non-app engine service
- Setting height of bwu-datagrid to dynamic
- use sass transformer in intellij dart
- Get 3D cube from an Obb3
- Send event from parent to child element in polymer.dart
- In the dart:io library, why would one want to set runInShell: true when calling Process.run?
- Can two @published properties have the same name
- dartanalyzer doesn't give a warning for missing implementation from interface
- WebStorm DartUnit with test api, run/debug error
- Polymer Dart - How can I read when core-list-dart is populated with data for a loading spinner?
- Refuse to load JS in Dart
- How to test Dart Polymer elements using the new Test library?
- Checking, if optional parameter is provided in Dart
Related Questions in SHAREDPREFERENCES
- Get value from shared preference in remoteview
- Share info between two processes - what's the safest way?
- SharedPreferences not save or whats wrong?
- Load strings from sharedpreferences in EditText (two classes)
- How to change PIN using SharedPreferences in Android?
- Update GridView in Asynctask doesn't work
- SharedPreferences NullPointerException Keeps Showing Up
- SharedPreferencesBackupHelper for an offline application
- Delete all sharedPreferences in Android
- SharedPreferences Null pointer exception
- How to store string / integer value in Broadcast receiver.?
- Sharing String between two applications
- Android Games: Strategies to Defeat Memory Editors for Cheating
- Android activity stopped unexpectedly
- .getContext() / this produces null object reference inside PreferenceActivity
Related Questions in UINT8LIST
- how to convert uint8list to png in dart using package:image.dart and manipulate the picture later on?
- How to avoid copying the bytes in Dart when deserializing an image from a Flatbuffer?
- Save a memory image (such as Uint8list) as image file in flutter
- get uint8list of network image in flutter web
- Uint8List to file
- Flutter Web How to Convert Uint8List to File
- Flutter uint8 (bgr8) Raw Image Data Convert to Picture
- Is there any way to access the video file path that converted to Uint8List
- base64Decode removes pages from a pdf in base64?
- what is the equivalent of ByteBuffer.wrap in dart?
- Flutter - How to put List<Uint8List> into shared preferences?
- Open generated file (Uint8list) in default application in Flutter
- dart null safety and typing issues
- Why this custom implementation slower than the built-in?
- Storing Uint8List into SQL Server
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
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.