我知道如何判断共享首选项中是否存在单个密钥,例如:
bool check = preferences.containsKey('weight');
但是,如果我想一次判断多个密钥,情况如下:
bool check = preferences.containsKey('weight','height',userName...ect);
是否可以以某种方式同时判断多个值?
我知道如何判断共享首选项中是否存在单个密钥,例如:
bool check = preferences.containsKey('weight');
但是,如果我想一次判断多个密钥,情况如下:
bool check = preferences.containsKey('weight','height',userName...ect);
是否可以以某种方式同时判断多个值?
SharedPreferences中没有这样做的方法,但您可以编写一个扩展方法,使其看起来像有:
extension SharedPreferencesExtensions on SharedPreferences {
bool containsAllKeys(Iterable<String> keys) {
return !keys.any((key) => !this.containsKey(key));
}
}
现在你可以这样称呼它:
bool check = preferences.containsAllKeys(['weight','height',userName...ect]);