Flutter如何转换列表< object>用于使用对象盒

发布于 2025-01-21 08:43:57 字数 481 浏览 1 评论 0原文

我有一个类似此代码的模型

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!);
  }

// ...

}

,并且有此错误

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

如何转换我的列表&lt; object&gt;存储在对象盒中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风渺 2025-01-28 08:43:57

您可以定义一个音符实体,并像文件夹一样与文件夹类创建一个与文件夹类别的关系。用户。

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

请叫√我孤独 2025-01-28 08:43:57

请这样做:
您定义默认构造函数并初始化变量注释
folder(){notes =&lt; notes&gt; []; }

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文