isar / isar/hive

Box values are empty even after insertion

Open
#715 4 comments 5 reactions 0 assignees View on GitHub
problem
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**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 _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('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 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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the Android case using _firebaseMessagingBackgroundHandler, Boxes.getConnections(), and the ValueListenableBuilder shown in the report. Check how the box is initialized and observed across the background handler and widget, using the listed Flutter, Hive, and hive_flutter versions. Done means a value inserted from the background notification is visible in the widget; the report does not specify the expected behavior beyond that.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, firebase, flutter
Domain
databases, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.