1

I am trying to assign value to the sharedPreference

sharedPreferences.setString('destination', 'supermarket');

But I'm having the following error.

Unhandled Exception: FormatException: Unexpected character (at character 1)

E/flutter ( 3073): supermarket

simsim
  • 155
  • 1
  • 11
  • 1
    Just for the sake of ruling this out, didn't you copy-paste the value from somewhere an invisible whitespace character could come before the 's'? – Dávid Laczkó Jun 04 '22 at 17:34
  • 1
    Uhm no. I even changed it to other values and I got the same error :( – simsim Jun 04 '22 at 18:06
  • 1
    Did you get instance of SharedPreferences. like this- final SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); – Babul Jun 05 '22 at 05:15
  • 1
    @Babul yes that's how I get it – simsim Jun 05 '22 at 05:53
  • Perhaps you need to change the value of `` in `pubspec.yaml` per [this](https://docs.flutter.dev/cookbook/persistence/key-value#1-add-the-dependency)? – Dávid Laczkó Jun 07 '22 at 09:43

0 Answers0