objectbox-dart icon indicating copy to clipboard operation
objectbox-dart copied to clipboard

@Property Annotation for getter/setter properties

Open khainke opened this issue 2 years ago • 1 comments

Currently, the @Property Annotation is only available for fields, that are defined as such in the @Entity.

Describe the solution you'd like

It would be nice to be able to add the @Property Annotation also to a getter (assuming a matching setter exists). This would just have the same effect on the property defined by the getter / setter pair as if it would have, would the annotation be attached to an equivalent field.

khainke avatar Mar 03 '22 16:03 khainke

Thanks! It's odd that this doesn't work already. Also @Transient on a getter does not appear to get recognized.

Edit: an internal issue for this exists.

greenrobot-team avatar Mar 08 '22 07:03 greenrobot-team

Same for @Index, reported originally in #528.

greenrobot-team avatar Apr 18 '23 05:04 greenrobot-team

Also freezed classes with non-required properties are affected by this, see #565.

greenrobot-team avatar Oct 17 '23 09:10 greenrobot-team

Annotating getters will be possible with the next release.

You will be able to do something like this:

@Property(type: PropertyType.date)
@Index()
DateTime get date => TODO;
set date(DateTime value) => TODO;

@Transient()
int get computedValue => TODO;
set computedValue(int value) => TODO;

greenrobot-team avatar Feb 12 '24 08:02 greenrobot-team