-1

I'm using shared_preference version 2.0.6, as per the documentation shared_preference version 0.5.6 by default supports web. as show in code 1st log works fine but the 2nd log not happening and in future builder showing

NoSuchMethodError: Unexpected Null Value

method not found

Receiver: null

Arguments: []

SharedPreferences prefs = await SharedPreferences.getInstance();
print("checking logged in user");//1st log
String loginedInUser = prefs.getString("user");
print("logged in user" + loginedInUser);//2nd log
vrb
  • 1
  • 1

1 Answers1

0

Ok, I found what was the problem, consider below code:

SharedPreferences prefs = await SharedPreferences.getInstance();
String loginedInUser = prefs.getString("user"); //2nd line
  • While using shared_preferences for Flutter web, getter key(user) can't be null means that if stored value of user is null 2nd line will not return null instead it shows an error, if the user has some data then returns that value.
  • While using SharedPreferences for Flutter in Android 2nd line returns null without any errors.
vrb
  • 1
  • 1
  • did you resolve the issue? In my app some values needed to have a null value, but shared_preferences in web breaks the app. – bringand1 Feb 22 '23 at 16:15