我正在尝试按照此SO 评论使用Hive读取 Box 的内容,但出现以下错误:
方法 'listenable' 没有为类型 'Box' 定义
有问题的代码是:
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()),
);
},
);
}
},
);
},
),
Run Code Online (Sandbox Code Playgroud)
pubspec.yaml:
hive: ^1.4.1+1
hive_flutter:
git:
url: git://github.com/hivedb/hive.git
path: hive_flutter
Run Code Online (Sandbox Code Playgroud)
我想要做的是在屏幕加载时列出框的内容。我似乎无法弄清楚我哪里出错了 - 任何指导将不胜感激!
| 归档时间: |
|
| 查看次数: |
2273 次 |
| 最近记录: |