我有一个简单的小部件,上面有一个按钮,按下该按钮后,数据就会随着颤抖的Hive软件包存储在硬盘中。
当检查元素列表时。
颤振产生以下错误。
E/flutter (22594): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: Class 'List<String>' has no instance method 'contain'.
为什么包含不起作用。
代码:
onTap: () async {
if (Hive.box("monthDataList").get("monthDataListKey") == null) {
Hive.box("monthDataList").put("monthDataListKey", [
dateTimeindex
]);
} else {
if (! Hive.box("monthDataList").get("monthDataListKey").contain(dateTimeindex)) {
Hive.box("monthDataList").put("monthDataListKey",Hive.box("monthDataList").get("monthDataListKey").add(dateTimeindex));
}
}
您正在寻找Iterable.contains
而不是Iterable.contains
。它检查是否可以在集合中找到给定的元素:
contain
if (!(...).contains(dateTimeIndex)) ...
扩展名 List
,这就是为什么您的List
对象具有Iterable
实例方法。