标签: flutter-isar

对 isar 数据库和 JsonSerialized 使用单个 Flutter 模型

我尝试使用单一模型来使用 Isar 在本地存储数据,并与 Retrofit 一起使用来处理 REST API 请求。

\n

Isar要求所有链接类都使用数据类型进行定义,IsarLink<MyClassName>JsonSerialized则要求使用它们MyClassName作为数据类型。

\n
@Collection()\n@JsonSerializable()\nclass UserGroup {\n  @JsonKey(ignore: true)\n  Id localId = Isar.autoIncrement; // you can also use id = null to auto increment\n\n  @ignore\n  @JsonKey(name: "_id")\n  String? id;\n\n  String name;\n  String description;\n\n  @ignore\n  Domain? domain;\n  \n  @ignore\n  UserGroupPermissions permissions;\n\n  @ignore\n  Organization? organization;\n\n  \n  @JsonKey(ignore: true)\n  IsarLink<Organization?> organization = IsarLink<Organization?>();\n\n  UserGroup({\n    this.id,\n    required this.name,\n    required this.description,\n    this.domain,\n    required this.permissions,\n    this.organization,\n  });\n\n  factory UserGroup.fromJson(Map<String, dynamic> json) …
Run Code Online (Sandbox Code Playgroud)

model retrofit flutter json-serializable flutter-isar

8
推荐指数
1
解决办法
2677
查看次数

如何将现有的 JSON 文件导入到 Isar flutter 中

大家好,我是 Isar Flutter 的新手。我想知道有什么方法可以将现有的 JSON 文件导入到 Isar 中吗?
我尝试在互联网上搜索此内容,但找不到太多内容。
下面是我的 Json 文件的结构。

{
 "food": [
    {
        "id": "0001",
        "name": "Cake",
        "description": [
            {
                "type": "Chocolate",
                "quantity": 1
            },
            {
                "type": "fruits",
                "quantity": 3
            },
            {
                "type": "Corn",
                "quantity": 6
            }
        ]
    },
    {
        "id": "0002",
        "name": "Raised",
        "description": [
            {
                "type": "Grape",
                "quantity": 6
            },
            {
                "type": "Wheat",
                "quantity": 2
            }
        ]
    }
],
"instruction": [
      {
        "category": "instruction_1002",
        "content": "abc1234"
      },
      {
        "category": "instruction_1003",
        "content": "def56789"
      }
  ]
}
Run Code Online (Sandbox Code Playgroud)

dart flutter flutter-isar

6
推荐指数
1
解决办法
1865
查看次数

我想在“Isar”中创建一个“collection”,但遇到了一个完全令人费解的错误并且遇到了麻烦

我想创建一个如下所示的集合,但是当我运行 flutter pub run build_runner build --delete-conflicting-outputs 时,出现以下错误。

import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:isar/isar.dart';

part 'model.freezed.dart';
part 'model.g.dart';

@freezed
@Collection(ignore: {'copyWith'}, inheritance: false)
class Model with _$Model {
  const factory Model({
    required String address,
  }) = _Model;
  Id get id => Isar.autoIncrement;
  const Model._();
}
Run Code Online (Sandbox Code Playgroud)

错误:

Constructor parameter does not match a property.
|
| required String address,
|
Run Code Online (Sandbox Code Playgroud)

尽管有一个简单的集合,但我遇到了错误并陷入困境。我该如何解决这个错误?

此外,在生成冻结文件时,不会创建 的.g.文件。Isar

dart flutter flutter-freezed flutter-isar

5
推荐指数
1
解决办法
190
查看次数