I am using hive and I am trying to listen to the value change of custom stored key as in the code below and I can't get any data ? So how can I achieve this ?
Stream<BoxEvent> listenToLocalCartItem(String cartItemId) {
var box = Hive.box('cart');
box.watch(key: cartItemId).listen((event) {
CartItemModel cartItem = event.value;
if (cartItem.numberOfItems > 0) {
emit(AddToCartState.showCartValue(cartItem.numberOfItems));
} else {
emit(AddToCartState.showAddButton());
}
});
}
On the other hand, I want to keep track of all data changes in the box as the code below like firestore snapshots and also I can't get any changes
Stream<Box> listenToLocalCart() {
Hive.openBox('cart').asStream().listen((event) {
_cartStatusProvider.cartItems = event.values.toList();
});
}