How can I store the list with sharedPreferences and use it in the ListView? this is my shared preferences codeand this is my list view
CodePudding user response:
To store list of string you can use the following:
List<String> stringsList= ['Alex', 'Mob', 'Flutter'];
final SharedPreferences prefs = await SharedPreferences.getInstance();
// store your string list in shared prefs
prefs.setStringList("stringList", stringsList);
To retrieve list of string you can use the following:
final SharedPreferences prefs = await SharedPreferences.getInstance();
List<String> myStringList = (prefs.getStringList('stringList') ?? List<String>());
CodePudding user response:
The answer to your question is here to save a list of objects to sharedpreferences and you can recall them in the commented place below:
itemBuilder(_,_){
//Recall the listview method
return yourWidget;}