Search code examples
flutterflutter-secure-storage

How to store object value in Flutter secure storage?


I have this error when I run App.

NoSuchMethodError (NoSuchMethodError: Class '_Map<String, dynamic>' 
has no instance method 'toJson'

This is my Code

await LocalStorage().addStorage('currentUser', json.encode(jsonResponse['data'][0].toJson()));

Solution

  • We can't know how you're parsing your JSON, but I would assume jsonResponse['data'] is already a map and does not require you to call .toJson(). The following should work:

    await LocalStorage().addStorage('currentUser', json.encode(jsonResponse['data'][0]));