List is not updated when using shared preferences

How to update a list in shared preferences ?

In Shared Preferences, we can also store a list in the form of a string. In the example below, a list of string data is stored in Shared Preferences as a string.

List data = ["3","4","5"]; 

storeData(data)async{
  SharedPreferences sh= await SharedPreferences.getInstance();
  
  sh.setString("newList",data.toString());// data store as a string
}

storeData(data);

If list of data update continuously but shared prefernces stored data not updated properly

sh.reload(); //After this perform logic to read data from Shared preferences
sh.getString("newList");// now every time list will be updated

Leave a Reply

Your email address will not be published. Required fields are marked *

web_horizontal
About Us ♢ Disclaimer ♢ Privacy Policy ♢ Terms & Conditions ♢ Contact Us

Copyright © 2023 ResearchThinker.com. All rights reserved.