isar / isar/hive

DateTime default value

Open
#974 4 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Dart
Stars
4.4k
Forks
449
PR merge metrics
No merged PRs in 30d

Description

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 !

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.