我正在开发 Flutter 应用程序并尝试将Moor包用于 DB。我已经在pubspec.yaml
文件中包含了所有依赖项,创建了我的表实体和数据库。
每次运行该应用程序时,都会出现此错误:
Dart Error: error: import of dart:mirrors is not supported in the current Dart runtime
这是pubspec.yaml
文件:
dependencies:
flutter:
sdk: flutter
http: ^0.12.2
moor: ^3.3.1
sqlite3_flutter_libs: ^0.2.0
path_provider: ^1.6.14
path: ^1.7.0
dev_dependencies:
moor_generator: ^3.3.1
build_runner: ^1.7.3
flutter_test:
sdk: flutter
这也是我的表实体:
class DBEntrie extends Table {
IntColumn get id => integer()();
TextColumn get uuid => text()();
TextColumn get name => text()();
TextColumn get title => text()();
@override
Set<Column> get primaryKey => {id};
}
和数据库类:
LazyDatabase _openConnection() {
return LazyDatabase(() async {
final dbFolder = await getApplicationDocumentsDirectory();
final file = File(p.join(dbFolder.path, 'entriesdb.sqlite'));
return VmDatabase(file, logStatements: true);
});
}
@UseMoor(tables: [DBEntries])
class MyDatabase extends _$MyDatabase {
MyDatabase() : super(_openConnection());
@override
int get schemaVersion => 1;
Future<List<DBEntrie>> getAllDBEntries() => select(_dBEntries).get();
}
它正确生成了表和数据库文件。但在运行时它给出了这个错误。我该如何解决?是否缺少任何依赖项?我应该更改应用程序使用的 Dart 版本吗?