registerAdapter does not work as shown in the example
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
To register a serializable object in Hive the method to use is:
`Hive.registerAdapter('Bee', Bee.fromJson);`
But, if you use the example code:
```
class Person {
String name;
int age;
Person(this.age, this.name); //<-- I had to add this, because name and age are not nullable
factory Person.fromJson(Map json) {
return Person(0, '')
..name = json['name'] as String
..age = json['age'] as int;
}
Map toJson() {
return {
'name': name,
'age': age,
};
}
}
Hive.registerAdapter('Person', Person.fromJson);
```
It does not compile the register Adapter method.
More over if I try to force to compile (with a cast) it takes an error at runtime.
Cannot use 4.0.0.dev2 , must use the 2.2.3 with @HiveType and HiveObject.
Contributor guide
No contributing guide indexed for this repository
Research direction
Compare the documented registerAdapter example with the 4.0.0.dev2 API and reproduce the reported compile and runtime errors. Check how the example differs from the 2.2.3 API, then update the example or clarify the supported usage so registration works for the documented version.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100