【发布时间】:2022-11-21 21:59:44
【问题描述】:
我正在尝试使用“retainWhere”将列表减少为只有匹配的值,但我收到的错误是
static Future getSearchHistory() async {
final value = await _storage.read(key: _keySearchHistory);
return value == null ? null : json.decode(value);
}
static Future setSearchHistory(history) async {
var results = await getSearchHistory();
print('results${results.runtimeType}');
if (results != null) {
var res = results.retainWhere(
(result) =>
result['value'].toLowerCase() ==
history['value'].toString().toLowerCase(),
orElse: () => null);
if (results != null) {
results.add(history);
final value = json.encode(results);
await _storage.write(key: _keySearchHistory, value: value);
}
} else {
final value = json.encode(history);
await _storage.write(key: _keySearchHistory, value: value);
}
}
【问题讨论】:
-
你能包括你的代码和你的错误信息吗?请不要为此使用图像。