Shared_Preferences for Flutter Web?

flutter sharedpreferences login
flutter shared_preferences example
flutter web url launcher
flutter sharedpreferences github
flutter gstreamer
flutter plugins
flutter magnetometer
flutter shared_preferences deprecated

Shared_preferences (https://pub.dev/packages/shared_preferences) doesn't seem to work for Flutter for Web.

I have the following function that's called when a button is pressed.

 getEmail() async {
    print("reached 1st line");
    SharedPreferences prefs = await SharedPreferences.getInstance();
    print("reached 2nd line");
    String _confirmedEmail = prefs.getString('_confirmedEmail') ?? "";
)

It prints "reached 1st line" but not "reached 2nd line", which means the program doesn't go past the await statement. Interestingly I don't get any error either. It seems to just ignore the rest of the function after the await statement.

What is the best alternative to store shared preferences in Flutter for Web?

Great news, from version 0.5.6 shared_prefs flutter supports web by default

Now it's includes shared_preferences for web

Your code should work without changes, just update dependency in pubspec.yaml

dependencies:
 shared_preferences: ^0.5.6

shared_preferences_web, Shared_preferences (https://pub.dev/packages/shared_preferences) doesn't seem to work for Flutter for Web. I have the following function that's called when a button is pressed. It prints "reached 1st line" but not "reached 2nd line", which means the program doesn't go past the await statement. To use this plugin in your Flutter Web app, simply add it as a dependency in your pubspec.yaml alongside the base shared_preferences plugin. (This is only temporary: in the future we hope to make this package an "endorsed" implementation of shared_preferences , so that it is automatically included in your Flutter Web app when you depend on package:shared_preferences .)

shared_preferences are not supposed to work with flutter web, that's why value of instance never returns. For this purpose, you can use any key-value stores instead, for example, sembast

UPD: the package supports web now since version 0.5.6

Shared_Preferences for Flutter Web?, Currently shared_preferences does not work using Flutter Web. There is no error, the future returned by SharedPreferences.getInstance()� Shared preferences plugin #. Wraps NSUserDefaults (on iOS) and SharedPreferences (on Android), providing a persistent store for simple data. Data is persisted to disk asynchronously.

I think it is supported now due to this. It depends on shared_preferences_web image from pub dev

[shared_preferences]: not working with Flutter Web � Issue #43943 , yaml file. dependencies: flutter: sdk: flutter shared_preferences: "<newest version >". Step 2: Import shared_preferences. Getting Started With Shared Preferences in Flutter If you want to store a small amount of persistent data that users can use later when they launch a mobile, using Shared Preferences is one of the ways to do it. Shared Preferences provides a way of reading and storing such data in a key-value pair.

You probably check the tags when you search for a library in pub.dev.

For the web the best way to implement that is implementing cache for web and dcache for implement that using flutter_web.

import 'package:dcache/dcache.dart';

void main() {
  Cache c = new SimpleCache(storage: new SimpleStorage(size: 20));

    c.set("key", 42);
    print(c.get("key")); // 42
    print(c.containsKey("unknown_key")); // false
    print(c.get("unknown_key")); // nil
}

As you can see, is very similar to shared_preferences for Flutter.

Hope this could help.

Store key-value data on disk, A common use-case of using Shared Preferences is when you want to store a JSON Web Token(JWT) on the app to authenticate users. Flutter� A reactive key-value store for Flutter projects. streaming_shared_preferences adds reactive functionality on top of shared_preferences. It does everything that regular SharedPreferences does, but it also allows listening to changes in keys. This makes it super easy to keep your widgets in sync with persisted values.

Using SharedPreferences in Flutter - FlutterDevs, How to Save Data to LocalStorage and SharedPreferences in Flutter. How to with the localstorage and shared_preferences plugin inside of our Flutter applications. How to Host a Flutter Web Project on Firebase Hosting. The main use of Shared Preferences is to save user preferences, settings, maybe data (if not too large) so that next time the application is launched, these pieces of information could be retrieved

Getting Started With Shared Preferences in Flutter, shared_preferences 0.5.7+3. Published May 21, 2020 • flutter.dev. 1.05K likes. Flutter Android iOS web. Readme � Changelog � Example � Installing; Versions. The Linux implementation of shared_preferences. Usage # Import the package # This package is an unendorsed Linux implementation of shared_preferences. In order to use this now, you'll need to depend on shared_preferences_linux. When this package is endorsed it will be automatically used by the shared_preferences package and you can switch to

How to Save Data to LocalStorage and SharedPreferences in Flutter, shared_preferences 0.5.7+3. Published 2020年5月21日 • flutter.dev. 1.05K likes. Flutter Android iOS web. Readme; Changelog; Example; Installing; Versions. How To Keep User Logged In Using Shared Preferences Flutter | Logout user using firebase If want code from website then check my website where I Upload code: (Check Desire language Category in

Comments
  • How long do these shared preferences persist? I'm seeing that when I do "flutter run -d chrome" I'm able to store things during that session that show up in that session, but if I hit refresh on my browser then I lose my shared prefs. Is that working as designed? is that related to running in debug mode perhaps?
  • @Eradicatore when I made "flutter build web" and then published on web hosting, it worked for me. Try this command and then launch main index HTML file.
  • Yup! I was wondering if that was maybe the case too. It indeed does work for me when I deployed it like that on a GCP VM. Thanks!
  • have you tested this for web?