【发布时间】:2020-10-23 23:03:46
【问题描述】:
我正在尝试使用 Hive 读取 Box 的内容,遵循 this SO 评论,但我收到以下错误:
没有为类型“Box”定义方法“listenable”
有问题的代码是:
FutureBuilder(
future: Hive.openBox<Contact>('testBox'),
builder: (context, snapshot) {
return ValueListenableBuilder(
valueListenable: Hive.box<Contact>('contacts').listenable(),
builder: (context, Box<Contact> box, _) {
if (box.values.isEmpty) {
return Text('data is empty');
} else {
return ListView.builder(
itemCount: box.values.length,
itemBuilder: (context, index) {
var contact = box.getAt(index);
return ListTile(
title: Text(contact.name),
subtitle: Text(contact.age.toString()),
);
},
);
}
},
);
},
),
pubspec.yaml:
hive: ^1.4.1+1
hive_flutter:
git:
url: git://github.com/hivedb/hive.git
path: hive_flutter
我要做的是在屏幕加载时列出框的内容。我似乎无法弄清楚我哪里出错了 - 任何指导将不胜感激!
【问题讨论】:
标签: flutter