Allow non-const default values
- Vorherrschende Sprache
- Dart
- Sterne
- 4.4k
- Forks
- 449
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
**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
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Start by tracing how @HiveField defaultValue is read and applied when a field is absent, then identify the entry point that currently requires a const expression. Define done as supporting a non-primitive default supplied through the proposed function form while preserving existing const defaults, with coverage for a missing field.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- dart
- Bereich
- database
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100