isar / isar/hive

Does not update , unless reinstalled

Open
#1,232 1 comment 1 reaction 0 assignees View on GitHub
question
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

**Question**
this is my function to initialize Hive and put some dummy data inside it if its empty , the but the data doesnt gets displayed , what i figured out is that its not even getting called on the hot restarts or reloads not even when i close the app the rebuild it , the only time the when i can see the updated values of the dummyDietPlan is when i uninstall the app and build it again , why is the _initializeHive() is only getting called once in the life time of the app ?
other than this issue , everything else working fine with hive , but just cant figure out why this issue is coming up

**Code sample**
```dart
void initState() {
super.initState();
_initializeHive();
_checkDietIsViewed();
}

Future _initializeHive() async {
if (!isInitialized) {
await HiveService.initHive();
setState(() {
isInitialized = true;
});
}
}

Future _initializeDummyData() async {
final dietPlans = await HiveService.retrieveDietPlan();
if (dietPlans.isEmpty) {
final dummyDietPlan = DietPlan( ... // dummy diet plan inserted
await HiveService.UpdateDietPlan(dummyDietPlan);
await HiveService.printDietPlans();
}
}

Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder>(
future: HiveService.retrieveDietPlan(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
} else if (snapshot.hasError) {
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
// Call _initializeHiveAndData() here to handle empty data
_initializeHive();
return Text('No diet plans available.');
} else {
final dietPlans = snapshot.data!;
return ListView.builder(
}
},
),
);
}
}

```

**Version**
Platform: iOS, Android
- Flutter version: [e.g. 1.5.4]
hive: ^2.2.3
hive_flutter: ^1.1.0
build_runner: ^2.4.6
hive_generator: ^2.0.0

Attaching the before and after reinstallation ScreenShots

![Screenshot (146)](https://github.com/hivedb/hive/assets/31371327/73406327-4a4d-4505-bee0-927744bc92fd)
![Screenshot (147)](https://github.com/hivedb/hive/assets/31371327/f8366056-29b1-44bf-9143-3fdd1ea5b7cd)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the initState, _initializeHive, _initializeDummyData, and FutureBuilder flow shown in the report, especially how HiveService initialization and data retrieval are ordered. There is no repository file or test named; done would mean identifying a reproducible initialization path in which updated dummy data appears without reinstalling the app.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart, 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.