Allow non-const default values
- Dominant language
- Dart
- Stars
- 4.4k
- Forks
- 449
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
We can now set default values. I think that's great, especially for when we introduce new non-nullable fields, so they're always guaranteed to have a value. The problem is that the default value needs to be a `const` expression. This means it can't be an instance of a subclass of `HiveObjectMixin` (which all of our non-primitive types are), because that doesn't have a `const` constructor.
Here's a simple example, say you have a new non-primitive field:
```
class NewComplexField with HiveObjectMixin {}
```
I would want to do:
```
class MyObject with HiveObjectMixin {
@HiveField(14, defaultValue: NewComplexField())
final NewComplexField complexField;
}
```
except that's not possible.
**Describe the solution you'd like**
I think it be fixed by having a function generate default values. Something like
```
class MyObject with HiveObjectMixin {
@HiveField(14, defaultValue: () => NewComplexField())
final NewComplexField complexField;
}
```
**Version**
- Platform: iOS, Android, Mac, Windows, Linux, Web
- Flutter version: 2.0.6
- Hive version: 2.0.4
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.