I am working on a Flutter app and trying to use Moor package for DB. I have included all dependencies in the pubspec.yaml
file, created my table entity and also the database.
Every time I run the app, I get this error:
Dart Error: error: import of dart:mirrors is not supported in the current Dart runtime
Here is the pubspec.yaml
file:
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
Here is also my table entity:
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};
}
and the DB class:
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();
}
It generated the table and the database file correctly. But at run it gives this error. How can I fix it? Is there any missing dependency? Should I change the Dart version I am using for the app?
The moor package that was previously published in pub.dev was discontinued and replaced by the new package drift. I suggest to use the latest plugin as this is being supported than the latter.