hive
hive copied to clipboard
Box values are empty even after insertion
Steps to Reproduce I am using firebase notification to get data. When data is received in background notification. I am adding to hiveBox Insertion is done successfully but when i tried to check the values i am getting empty box. Code sample
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print('_firebaseMessagingBackgroundHandler CALLED');
await Firebase.initializeApp();
try {
await Hive.initFlutter();
Hive.registerAdapter(ConnectionsAdapter(), override: true);
if (!Hive.isBoxOpen('connection_box')) {
await Hive.openBox<Connections>('connection_box');
}
if (message.data['messageType'] == 'connection_request') {
final connection = Connections()
..id = DateTime.now().microsecond.toInt()
..connectionState = 'Pending'
..userName = event.data['userName'];
final box = Boxes.getConnections();
await box.put('${event.data['senderId']}', connection);
print('BOX in INSERTED PERFECTLY');
}
} catch (e) {
print('${e.toString()} Exception');
}
And then in widget
ValueListenableBuilder(
valueListenable: Boxes.getConnections().listenable(),
builder: (BuildContext context, Box<Connections> box, _) {
final connection = box.values.toList();
print(box.values);
print('BOX VALUES');
},);
Version
- Platform: Android
- Flutter version: 2.2.1
- Hive version: hive: ^2.0.4 hive_flutter: ^1.0.0