I'm trying to read the contents of a Box using Hive, following this SO comment, but I get the following error:
The method 'listenable' isn't defined for the type 'Box'
The code in question is:
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
What I am trying to do is list the content of the box when the screen loads. I can't seem to figure out where I am going wrong - any guidance would be greatly appreciated!
The solution: hive_flutter.dart needs to be imported first
import 'package:hive_flutter/hive_flutter.dart';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With