Adding new field to Hive Object results in error from Adapter
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Question**
I've added 2 new fields to my existing Hive Object. I followed the rules, didn't change the HiveType and also the new fields have new HiveField numbers. I generated the new adapter using the command
`flutter packages pub run build_runner build`
The problem is that when I run my app and openBox is executed, the following exception is thrown:
`Unhandled Exception: type 'Null' is not a subtype of type 'String' in type cast`
I can see through console that the new fields are the problem, because the previous stored data in that box didn't have that fields. I read the documentation and there says that this is not supposed to happen.
**Code sample**
```dart
await Hive.initFlutter();
Hive.registerAdapter(ProductsAdapter());
await Hive.openBox("favorite_products"); // this throws the exception
```
**Version**
- Platform: iOS, Android
- Flutter version: 2.2.1
- Hive version: 2.0.4
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure from the provided Hive.initFlutter, ProductsAdapter registration, and Hive.openBox entry point using existing stored data. Inspect the generated ProductsAdapter and the field-reading path; done means an existing box opens after new fields are added, with coverage for previously stored data.
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
- Mostly clear
- Newbie friendliness
- 35/100