0

我决定在我的下一个项目中使用Isar 数据库,我发现它在处理本地数据时非常有用。

我按照其网站上的快速入门指南进行操作。我添加了依赖项。注释了联系人类。Ran 代码生成器。但在第四步,我在创建 Isar 实例时创建架构时遇到问题。

initIsar() async {
  final dir = await getApplicationSupportDirectory();
  final isar = await Isar.open(
    schemas: [ContactSchema],
    directory: dir.path,
    inspector: true,
  );
}

问题是我在哪里输入了 ContactSchema,它说

Undefined name 'ContactSchema'.
Try correcting the name to one that is defined, or defining the name.

所以我要问的问题是,我遵循了指南,但我无法创建模式。如何创建一个以使 Isar db 工作?

更新:

import 'package:isar/isar.dart';

part 'contact.g.dart';

@Collection()
class Contact {
  @Id()
  int? id;

  late String name;
}

添加后part 'contact.g.dart',输入此命令flutter pub run build_runner build即可。

4

1 回答 1

0

你好 Zahid 如果你想在你的下一个 Flutter 应用程序中添加本地数据库,那么https://pub.dev上有各种包。

我强烈建议您从https://pub.dev/packages/floor开始,它很容易学习轻量级的使用..

试试这个你会喜欢的。如何实现你可以谷歌它,这里有一个关于如何在你的颤振移动应用程序中使用 Floor 的教程。

https://www.youtube.com/watch?v=cQ7W7vpwTbk&t=1055s

于 2022-02-10T11:16:35.003 回答