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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With