我可以在Flutter中将List放入SharedPreferences中吗? [英] Can i put List into SharedPreferences in Flutter?
本文介绍了我可以在Flutter中将List放入SharedPreferences中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以将 ArrayList
或 List
对象放入 SharedPreferences
在Flutter吗?因为我只是意识到颤振并没有使飞镖飞起来
Can I put ArrayList
or List
object to SharedPreferences
in Flutter? Cause I just realized that flutter haven't gson in their dart
所以..我想通过点击星形图标来保存喜欢的书,当我点击时,图书将保存在sharedPreferences中。
So..i want to save like favorite books by tapping star icon, and when I tap that, that books will be saved in sharedPreferences.
我可以看到我最喜欢的图书列表。
and I can see the list of my favorite books.
推荐答案
您可以将 List< String>
保存在<$ c $中c> SharedPreferences 。这是您应该如何做。
You can save List<String>
in SharedPreferences
. Here is how you should do it.
prefs.setStringList("key", yourList);
SharedPreferences prefs;
List<String> list;
// ...
Future<bool> _saveList() async {
return await prefs.setStringList("key", list);
}
List<String> _getList() {
return prefs.getStringList("key");
}
这篇关于我可以在Flutter中将List放入SharedPreferences中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文