1

I use ObjectBox (3.0.0) on flutter/dart to implement the database part. In an Entity, I am looking to add an enumeration type list.

enum ExampleEnum {
    exampleOne,
    exampleTwo,
    ...
}


@Entity()
class Examples {
  /// ObjectBox 64-bit integer ID property, mandatory.
  int id = 0;

  /// List of Examples.
  List<ExampleEnum> examples = [];
}

I get this warning :

[WARNING] objectbox_generator:resolver on lib/entity/examples.dart:
  skipping property 'examples' in entity 'Examples', as it has an unsupported type: 'List<ExampleEnum>'

If I try to store only enumeration index in place ExampleEnum type by List i get this error :

[WARNING] objectbox_generator:resolver on lib/entity/examples.dart:
  skipping property 'examples' in entity 'Examples', as it has an unsupported type: 'List<int>'

How I can store a list of enumeration type correctly in my Entity ?

Dev Loots
  • 708
  • 9
  • 28

1 Answers1

1

At this point (January 2022), a list of enum values are not directly supported. One workaround are type converters which allow custom types.

Markus Junginger
  • 6,950
  • 31
  • 52
  • In my case, `List examples;` should be : `@Property(type: PropertyType.byteVector) List examples;` where int is index of my enum ? Have you any other example ? – Dev Loots Jan 21 '22 at 12:50
  • The linked to page has [an example using a single enum](https://docs.objectbox.io/advanced/custom-types#convert-annotation-and-property-converter). As well as [recommendations for storing enums](https://docs.objectbox.io/advanced/custom-types#how-to-convert-enums-correctly). You would have to change it to work with a list of enums though. – Uwe - ObjectBox Jan 24 '22 at 06:28