我尝试使用一些共享首选项方法,如setStringList
和getStringList
,但在使用get和显示其值时 我在控制台上看到下面这行代码:
{0: Instance of 'SearchDelegateModel', 1: Instance of 'SearchDelegateModel'}
下面是代码:
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条答案
按热度按时间sdnqo3pr1#
你可以共享
SearchDelegateModel
,或者你可以像这样访问你的数据模型。print("${getpre[0].nameVariableInSearchDelegateModel}");
vqlkdk9b2#
通过查看代码,您可以在打印行中使用它