Open rubenvereecken opened 3 years ago
Unfortunately codegeneration for default values is limited by constant values. What you can do is you can write your own adapter to supply non-constant value.
Unfortunately codegeneration for default values is limited by constant values. What you can do is you can write your own adapter to supply non-constant value.
Can you give an example of your suggestion? I am trying to do something like this too
class PatientData extends HiveObject {
@HiveField(0,defaultValue:AccessToken())
AccessToken? accessToken;
any further information on how I can support the non-constant value?
any further information on how I can support the non-constant value?
Not tested but you might try:
What's stopping you from doing this?
@HiveType(typeId: 6)
class ConstructorDefaults {
ConstructorDefaults({
DateTime? d,
}) : d = d ?? DateTime.now();
@HiveField(3)
final DateTime d;
}
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 ofHiveObjectMixin
(which all of our non-primitive types are), because that doesn't have aconst
constructor.Here's a simple example, say you have a new non-primitive field:
I would want to do:
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
Version