I am trying to use some shared preferences methods such as setStringList
and getStringList
but when using the get and displaying its values I get the following line on the console:
{0: Instance of 'SearchDelegateModel', 1: Instance of 'SearchDelegateModel'}
Here is the code:
IconButton(
icon: Icon(Icons.search),
onPressed: () async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final busqueda = await showSearch(context: context, delegate: SearchDelegateMenuPrincipal("Buscar...", this.historialMenuPrincipal));
if (busqueda != null) {
historialMenuPrincipal.removeWhere((item) => item.apodo == busqueda.apodo);
this.historialMenuPrincipal.insert(0, busqueda);
final historialbusquedacastead = historialMenuPrincipal.map((e) => e.toString()).toList();
prefs.setStringList("HistorialBusquedaPreferences", historialbusquedacastead);
var getpre = prefs.getStringList("HistorialBusquedaPreferences");
print(getpre.asMap()); // the print shows {0: Instance of 'SearchDelegateModel', 1: Instance of 'SearchDelegateModel'}
}
},
),
//////////
List MenuPrincipalViewproductFromJson(String str) => List<SearchDelegateModel>.from(json.decode(str).map((x) => SearchDelegateModel.fromJson(x)));
SearchDelegateModel{
String apodo;
String name;
SearchDelegateModel({this.apodo,this.name})
}
factory SearchDelegateModel.fromJson(Map<String, dynamic> parsedJson){
return SearchDelegateModel(
name: parsedJson['name'],
apodo : parsedJson['apodo'])}
2
Answers
Can you share
SearchDelegateModel
, or you can access you data model like this.print("${getpre[0].nameVariableInSearchDelegateModel}");
By looking at your code, you could use this in your print line instead