Flutter how to convert List<Object> for using ObjectBox

609 views Asked by At

I have a model like this code

class Folder {
  int id;
  String title;
  Color? color;
  List<Note> notes;

  final user = ToOne<User>();

  String? get dbNotes => json.encode(notes);

  set dbNotes(String? value) {
    notes = json.decode(value!);
  }

// ...

}

and I have this error

Cannot use the default constructor of 'Folder': don't know how to initialize param notes - no such property.

How can I convert my List<Object> to store in ObjectBox?

2

There are 2 answers

0
Anna - ObjectBox On

You can define a Note entity and create a To-One relation to the Folder class just like you did with Folder -> User.

0
flutterman On

Please do this: you define a default constructor and initialize the variable notes Folder(){ notes = <Notes>[]; }