Minimal working example:
import 'package:hive/hive.dart';
part 'person.g.dart';
@HiveType(typeId: 1)
class Person extends HiveObject {
@HiveField(0)
HiveList<Person> friends;
Person(this.friends);
}
The (redacted) generated code is as follow:
.
.
.
class PersonAdapter extends TypeAdapter<Person> {
@override
final int typeId = 1;
@override
Person read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = <int, dynamic>{
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return Person(
(fields[0] as HiveList)?.castHiveList(),
);
}
.
.
.
The (type) error is:
The argument type 'HiveList<Person>?' can't be assigned to the parameter type 'HiveList<Person>'
The line (fields[0] as HiveList)?.castHiveList() is wrong because is nullable but friends is not. Here the problem is the use of the ?. operator over a non nullable expression ((fields[0] as HiveList))
Minimal working example:
The (redacted) generated code is as follow:
The (type) error is:
The line
(fields[0] as HiveList)?.castHiveList()is wrong because is nullable butfriendsis not. Here the problem is the use of the?.operator over a non nullable expression ((fields[0] as HiveList))