【发布时间】:2019-04-17 18:03:12
【问题描述】:
我想获取除两个键之外的所有 SharedPreferences 键
我不能使用 getString(Key) 方法,因为有 N 个键。
Future<List<Widget>> getAllPrefs() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
// I won't print those two keys neither remove them
// prefs.remove("lib_cached_image_data");
// prefs.remove("lib_cached_image_data_last_clean");
prefs.setString("Market", "position");
prefs.setString("Home", "position");
return prefs.getKeys().map<Widget>((key) {
//this is incorrect
if (key != "lib_cached_image_data" && key != "lib_cached_image_data") {
ListTile(
title: Text(key),
subtitle: Text(prefs.get(key).toString()),
);
}
}).toList(growable: false);
}
我希望输出:所有 ("Keys", "Values") 除了 ("lib_cached_image_data",value) , ("lib_cached_image_data_last_clean",value)
【问题讨论】: