How can i store variable or to say list variable in the local storage in flutter?

620

You can store it in shared preferences , add the shared_preferences plugin to the pubspec.yaml file::

dependencies:
  flutter:
    sdk: flutter
  shared_preferences: "<newest version>"

Save data like :

// obtain shared preferences
final prefs = await SharedPreferences.getInstance();

// set value
prefs.setInt('counter', counter);

And finally read data using :

final prefs = await SharedPreferences.getInstance();

final counter = prefs.getInt('counter') ?? 0;

Note : Only primitive types can be used: int, double, bool, string, and stringList. It’s not designed to store a lot of data.

Share:
620
user11908262
Author by

user11908262

Updated on December 24, 2022

Comments

  • user11908262
    user11908262 over 1 year

    I am creating an music player app which needs to list down the music tile after user selected audio files from mobile local storage. So i need to store all the music files path in the local storage so when user selected music one time from local storage he/she did not need to select second time. I does not figure it out how can i do that. I use file_picker for selecting files and path_provider for storing the local data. Could you please help me with this situation please?