Hive Generator strips nullability of generics
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Steps to Reproduce**
When running `flutter pub run build_runner build`
**Code sample**
```
@HiveType(typeId: 1)
class HiveLocation extends HiveObject {
@HiveField(0)
CustomObject? address;
}
```
Provide a few simple lines of code to show your problem.
Hive Generator generates:
```
@override
HiveLocation read(BinaryReader reader) {
final numOfFields = reader.readByte();
final fields = {
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return HiveLocation()..address = fields[0] as CustomObject?;
}
```
Cannot assign `CustomObject?` to `CustomObject?`.
This is fixed by making a change to `class_builder.dart`:
```
String _displayString(DartType e) {
return '${e.getDisplayString(withNullability: true)}';
}
```
I believe that the current implementation of `_displayString` is a remnant of pre-nullsafety code.
**Version**
- Platform: Mac, but probably all
- Flutter version: 2.2.3
- Hive Generator version: 1.1.1
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.