Class'List '没有实例方法'contain'。飞镖

问题描述 投票:0回答:1

我有一个简单的小部件,上面有一个按钮,按下该按钮后,数据就会随着颤抖的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));
}
}
flutter dart contains
1个回答
0
投票

您正在寻找Iterable.contains而不是Iterable.contains。它检查是否可以在集合中找到给定的元素:

contain

if (!(...).contains(dateTimeIndex)) ... 扩展名 List,这就是为什么您的List对象具有Iterable实例方法。

© www.soinside.com 2019 - 2024. All rights reserved.