hive icon indicating copy to clipboard operation
hive copied to clipboard

DateTime default value

Open TheCarpetMerchant opened this issue 3 years ago • 4 comments

I'd like to be able to specify DateTime(0) as a default value for DateTime objects. Of course you can't do this because DateTime(0) isn't const. A solution for this would be to specify true as the default value, which would actually generate DateTime(0) in the adapter.

One solution specifying true as the default value, which generates wrong code, but the error raised by the Dart compiler allows you to make the correction manually in the generated file. It's incredibly bad practice, I know. A better alternative is to have these fields be nullable, and use getters and setters. I don't like this approach because it adds unnecessary layers, but whatever works I guess.

Would it be possible to do this in a timely manner ? If not, I'll go with the nullable fields approach. It just annoys me because I'll then practically be stuck with these nullable fields and their accessors forever.

Thanks !

TheCarpetMerchant avatar May 22 '22 18:05 TheCarpetMerchant

I agree. A general solution would be great. Extending an existing Hive table is currently complicated. When adding a new HiveField which type is a new HiveType, I have to use this nullable approach, because I can not create a const constructor for a HiveObject.

WasaLordy avatar Jul 16 '23 15:07 WasaLordy