In moor flutter, keywords select, into, update, delete
show error as below-
error: Couldn't infer type parameter 'R'. Tried to infer 'Lists' for 'R' which doesn't work: Type parameter 'R' declared to extend 'DataClass'. The type 'Lists' was inferred from: Parameter 'table' declared as 'TableInfo'but argument is '$ListsTable'. Consider passing explicit type argument(s) to the generic.
import 'package:moor_flutter/moor_flutter.dart';
import 'package:moor/moor.dart';
part 'List.g.dart';
@DataClassName('Lists')
class Lists extends Table{
IntColumn get id => integer().autoIncrement()();
TextColumn get name => text().withLength(min:1, max: 50)();
DateTimeColumn get date => dateTime().nullable()();
BoolColumn get strikeThrough => boolean().withDefault(Constant(false))();
}
@UseMoor(tables: [Lists])
class AppDatabase extends _$AppDatabase {
AppDatabase(): super((FlutterQueryExecutor.inDatabaseFolder(path:'db.sqlite',logStatements:true)));
@override
int get schemaVersion => 1;
Future<List<Lists>> getAllLists() => select(lists).get();
Stream<List<Lists>> watchAllLists() => select(lists).watch();
Future insertLists(Lists list) => into(lists).insert(list);
Future updateLists(Lists list) => update(lists).replace(list);
Future deleteLists(Lists list) => delete(lists).delete(list);
}
You are using Lists
class in these functions
Future<List<Lists>> getAllLists() => select(lists).get();
Stream<List<Lists>> watchAllLists() => select(lists).watch();
Future insertLists(Lists list) => into(lists).insert(list);
Future updateLists(Lists list) => update(lists).replace(list);
Future deleteLists(Lists list) => delete(lists).delete(list);
which is the moor tables related class. You should be using List
class. However I would suggest to rename your table because Dart already have a List
class.
From the docs, you can see that Todos
getter comes with a Todo
(singular) class :
// inside the database class, the `todos` getter has been created by moor.
@UseMoor(tables: [Todos, Categories]) // Todos getter
class MyDatabase extends _$MyDatabase {
Future<List<Todo>> get allTodoEntries => select(todos).get(); // Todo class
// ^ no "s" here
Stream<List<TodoEntry>> watchEntriesInCategory(Category c) {
return (select(todos)..where((t) => t.category.equals(c.id))).watch();
}
}