Allow non-const default values
- Lingua principale
- Dart
- Stelle
- 4.4k
- Fork
- 449
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
**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
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Valutazione
Questa issue non è ancora stata valutata.