Questions tagged [flutter-sharedpreference]

Flutter plugin for reading and writing simple key-value pairs. Wraps NSUserDefaults on iOS and SharedPreferences on Android.

Wraps platform-specific persistent storage for simple data (NSUserDefaults on iOS and macOS, SharedPreferences on Android, etc.). Data may be persisted to disk asynchronously, and there is no guarantee that writes will be persisted to disk after returning, so this plugin must not be used for storing critical data.

Visit: shared_preferences

114 questions
1
vote
0 answers

How to show a popup everytime user login to the app flutter

I am trying to show a popup saying Become a member everytime user login to the app. If he logout from the app and login again the pop up should show saying Become a member. Using SharedPreference I am able to do it only once whenever the user login…
Lav Sharma
  • 327
  • 1
  • 5
  • 23
1
vote
1 answer

How do I save Map> in sharedPreferences in flutter?

I'm trying to save a Map> in sharedPreferences. I tried to use the classic sharedPreferences package, but I'm having trouble. If I save a string to sharedPreferences, then when I try to retrieve and use json.decode(...), I get…
1
vote
1 answer

Late initialization of a Theme in Flutter

I'm trying to implement dark and light themes in my Flutter app. To do this, I'm using a ViewModel approach to notify the whole application when the theme changes. When a user changes the theme, I'm saving it using shared_preferences. When the…
vtomic85
  • 590
  • 1
  • 11
  • 32
1
vote
2 answers

JsonDecoding Shared Preferences returning List instead of List

I have a list contacts that stores Contact which is a type acquired from contact_services package List contacts = []; and I store the List using SharedPrefrences by first jsonEncode it and then save it void saveContacts() async{ …
Anan Saadi
  • 328
  • 4
  • 21
1
vote
3 answers

The non-nullable variable '_preferences' must be initialized. Try adding an initializer expression

I am trying to implement a class where i can call SharedPreferences funtions. import 'package:shared_preferences/shared_preferences.dart'; class UserPreferences { static SharedPreferences _preferences; static const _keyToken = 'token'; …
1
vote
2 answers

Flutter Null Safe Config Class with shared_preferences

In flutter 1.x, I implemented a Config class using the Flutter shared_preferences package; the code looks like this: import 'package:shared_preferences/shared_preferences.dart'; class Config { static final Config _config = Config._internal(); …
johnwargo
  • 601
  • 2
  • 7
  • 22
1
vote
2 answers

How keep user logged in flutter

I posted yesterday this question but i didn't get any valid answer. My current situation is i can successfully log the user in but when i restart the app i have to login again so i need to save the details of the user in a shared preference so that…
lucky
  • 185
  • 5
  • 18
1
vote
0 answers

Flutter Shared Pref Returning Multiple Instances instead of one between foreground and background

Everything works perfectly as long as app is running foreground. This part is for handling background firebase message and preparing notification object and saving the received notification. This part writes json encoded notification message to…
1
vote
1 answer

How to store data as array in getStringList(Shared Preference) in Flutter

I am trying to store the array of documentId when the user click's on the screen. I tried to write and load the data using SharedPreference but it is stored as a string, not as an array. MyCode: _writedata() async{ final prefs = await…
Elam
  • 413
  • 6
  • 19
1
vote
2 answers

Flutter - SharedPreference not saving value - Returning NULL all time

I have implemented SharedPreference in Flutter using the following dependency: shared_preferences: ^0.5.12+4 My Preference class : class Preference { static Future _prefs = SharedPreferences.getInstance(); static…
0
votes
1 answer

Non-nullable instance of SharedPreferences must be initialized in Flutter

I want to store and read details using local storage. I have added dependencies in the pubspec.yaml file and imported the shared_preferences class. Hint showed to add late before SharedPreferences prefs; after adding late, app doesn't store…
0
votes
1 answer

How to Cache Selected Items from a Multi-Select Dropdown in Flutter

I have a Flutter application where users can select multiple options from a dropdown using the dropdown_search package. I would like to add a feature where the selected items are cached locally, and then pre-populated when the user comes back to the…
Gladiator
  • 354
  • 3
  • 19
0
votes
2 answers

The default theme is displayed for a moment when the app is launched. [Flutter]

Themes are switched using RIverpod; ThemeMode is saved using Shared Preferences. They are working fine.But when I set the default values as follows, the default theme is shown for a moment at the beginning. That is ugly. late ThemeMode _themeMode =…
Kaya
  • 13
  • 2
0
votes
1 answer

Flutter shared_preferences sometimes not initialized when using the Singleton pattern - one instance across all files

So I have created a class for using shared_preferences with a singleton pattern, so I can use one instance across all my files. And almost all of the time it works flawlessly, but occasionally, when I am not using the app but it is still open in the…
0
votes
1 answer

Is it possible to allow multiple entities to use one global ChangeNotifier in flutter?

I'm designing an application that allows users to view content of their desired integrations (this could be anything such as twitter, bbc.co.uk etc...). I have a settings page in which I would like the user to authenticate the services they would…