You can listen/watch specific key changes as a Stream
with the watch()
like this:
class MyStatefulWidget extends StatefulWidget {
const MyStatefulWidget({super.key});
@override
State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}
class _MyStatefulWidgetState extends State<MyStatefulWidget> {
@override
void initState() {
Hive.box("myBox").watch(key: "myKey").listen((event) {
print("BoxEvent | key: ${event.key}, value: ${event.value}, deleted: ${event.deleted},");
specificMethod(event.value);
});
super.initState();
}
like the example, you can get the actual key
, value
, deleted
( returns a bool
).
And every time it's changed the specificMethod()
method will execute.