google / google/built_value.dart
How to set a default value on a non-instantiable class?
- Dominant language
- Dart
- Stars
- 886
- Forks
- 195
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 4
Description
I was trying to migrate the example folder to NNBD and I'm stuck on `example/polymorphism.dart`:
The abstract class Animal has an attribute `legs` which I believe should not be nullable.
I tried using BuiltValueHook to set a default value but it's only considered if the class is instantiable:
```dart
@BuiltValue(instantiable: false)
abstract class Animal extends Object with Walker {
// Set the default value of legs to 0
@BuiltValueHook(initializeBuilder: true)
static void _setDefaults(AnimalBuilder b) => b..legs = 0;
@override
int get legs;
Animal rebuild(void Function(AnimalBuilder) updates);
AnimalBuilder toBuilder();
}
```
Is there a way to make sure the implementing classes (ex: Cat) inherit the hook?
Contributor guide
Assessment
This issue has not been assessed yet.