wahyu
wahyu

Reputation: 2425

How to update value inside shared preferences in flutter

actually when saving data inside shared preferences.. I am using this code

add() async {
  SharedPreferences prefs = await SharedPreferences.getInstance();
  prefs.setString('data', "ok");
}

but, is there a way to update the value of data for example I want to change ok into fine because when I try to re-save my data using that code... and call it using prefs.getString('data'); it always shows the old data not the update one

Upvotes: 1

Views: 11558

Answers (2)

gsm
gsm

Reputation: 2426

//shared-preferences

 SharedPreferences prefs = await SharedPreferences.getInstance();
        prefs.setString('profileImg', data1['imagePath']);
        prefs.setString('un', data1['username']);

Upvotes: 0

Bassem Abd Allah
Bassem Abd Allah

Reputation: 296

Just reassign it again

prefs.setString('data', "fine");

Upvotes: 12

Related Questions