【问题标题】:Flutter how to convert List<Object> for using ObjectBoxFlutter 如何转换 List<Object> 以使用 ObjectBox
【发布时间】:2022-09-30 18:11:41
【问题描述】:

我有这样的代码模型

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.

如何将我的 List<Object> 转换为存储在 ObjectBox 中?

    标签: flutter objectbox flutter-objectbox


    【解决方案1】:

    您可以定义一个 Note 实体并创建与 Folder 类的一对一关系,就像您对 Folder -> User 所做的那样。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 2023-03-08
        • 2020-11-27
        • 2019-12-06
        • 2017-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-27
        相关资源
        最近更新 更多