isar / isar/hive

How to update the app when there is a new box?

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

Description

**Question**
I'm wondering how to handle updates from the play/app store when I release an update that includes a new box. Right now, I have a function named defaultState that is run when the app opens for the first time or when the user chooses to reset all data. In this, I clear my boxes and add data. So when I push an update to the app, it is my understanding that the defaultState function will not be called, and thus the new box won't get data, which will break the app. How would I handle this?

**Code sample**
```dart
void main() async {
// on first time opening app, sets to default state
SharedPreferences prefs = await SharedPreferences.getInstance();
bool? resetToDefault = prefs.getBool('resetToDefault');

// if first time opening app
if (resetToDefault == null || resetToDefault) {
defaultState();
}
}

// sample of defaultState. Notice data added to boxes
void defaultState() async {
Box boolBox = Hive.box('boolBox');
boolBox.deleteAll(boolBox.keys);
boolBox.add(true);
}
```

**Version**
- Platform: iOS, Android
- Flutter version: 3.1.0-0.0.pre.1227
- Hive version: whatever is most recent

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.