objectbox / objectbox-dart

Flutter database for super-fast Dart object persistence
https://docs.objectbox.io/getting-started
Apache License 2.0
1.02k stars 117 forks source link

Cannot figure out default value for field: Salescategory salesCategory #647

Closed yashanghan22 closed 3 months ago

yashanghan22 commented 3 months ago

cannot generating g dart file using objectbox package just because of my class has one custom type enum parameter which is causing a issue don't know it is issue or not so want to know is there any solution for this ?????

Build info

Expected behavior

it should generate g dart file if i put any enum parameter in the class

Actual behavior

it is not generating dart file and throwing error as shown below in th screenshot image

Code

Code ```dart @Entity() class SalesConverterModel { @Id() int? id; @Property() Salescategory salesCategory; PartyModel? partyName; String? broker; String? onAc; String? outstate; String? qaulity; SalesConverterModel({ this.id, this.salesCategory = Salescategory.sales, this.partyName, this.broker, this.onAc, this.outstate, this.qaulity, }); } ```
greenrobot-team commented 3 months ago

ObjectBox can not know how to convert SalesCategory to a database value, even if you add the @Property annotation. It needs to be mapped to a supported type, like an int or String. See https://docs.objectbox.io/advanced/custom-types#convert-annotation-and-property-converter for an example.

Note: labeled this issue with "more info required" so it will auto-close in a few days if there are no follow-up comments.

yashanghan22 commented 3 months ago

@greenrobot-teamI, I understand that I need to assign values to each enum property, correct?

greenrobot-team commented 3 months ago

You need to add methods to convert to a database value, like shown at https://docs.objectbox.io/advanced/custom-types#convert-annotation-and-property-converter

yashanghan22 commented 3 months ago

@greenrobot-team, got it. Thanks for the solution.