I have saved json data in SharedPreferences like this
storage.setString("user", userInfo);
now I want to edit value inside userInfo which consist of name & phone number ,
so what I can do to change the value like the name
// get your json
var source = prefs.getString('user');
var json = jsonDecode(source);
// make changes
json['userInfo'] = {
'name': 'new name',
'phoneNo': 'new number'
};
// put it back
prefs.setString('user', jsonEncode(json));
first of all import the convert library;
import 'dart:convert';
get your jsonString
String jsonString = await storage.getString("user");
and decode it to Dart;
var yourJson = json.decode(jsonString);
Edit your json and convert it to String again;
String editedJsonString = json.encode(yourJson);
finally save it to shared with same key;
storage.setString("user", editedJsonString);