在Flutter中使用moor时使用关键字出错
Error in using keywords while using moor in Flutter
在moor flutter中,关键字select, into, update, delete
显示错误如下-
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);
}
您正在这些函数中使用 Lists
class
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);
这是沼泽 table 相关的 class。您应该使用 List
class。但是我建议重命名你的 table 因为 Dart 已经有一个 List
class.
从docs可以看出Todos
getter带有一个Todo
(单数)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();
}
}
在moor flutter中,关键字select, into, update, delete
显示错误如下-
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);
}
您正在这些函数中使用 Lists
class
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);
这是沼泽 table 相关的 class。您应该使用 List
class。但是我建议重命名你的 table 因为 Dart 已经有一个 List
class.
从docs可以看出Todos
getter带有一个Todo
(单数)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();
}
}