You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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<String, dynamic> json) {
return Person(0, '')
..name = json['name'] as String
..age = json['age'] as int;
}
Map<String, dynamic> 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.
The text was updated successfully, but these errors were encountered:
All this is with hive 2.2.3
You have this enum for example
with all the hive annotation
hive will create an adapter for you
inside 'distance_unit.g.dart'
Thats the adapter you have to register
if you dont use the hive annotations you still can do it but you have to create the adapter by hand
To register a serializable object in Hive the method to use is:
Hive.registerAdapter('Bee', Bee.fromJson);
But, if you use the example code:
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.
The text was updated successfully, but these errors were encountered: