How to store object value in Flutter secure storage?

185 Views Asked by At

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()));
1

There are 1 best solutions below

0
On BEST ANSWER

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]));