0

在 moor flutter 中,关键字select, into, update, delete显示错误如下-

错误:无法推断类型参数“R”。试图推断“R”的“列表”不起作用:类型参数“R”声明为扩展“DataClass”。'Lists' 类型推断自:参数 'table' 声明为 'TableInfo' 但参数是 '$ListsTable'。考虑将显式类型参数传递给泛型。

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);    
}
4

1 回答 1

0

Lists在这些函数中使用类

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);    

这是与沼泽桌相关的课程。你应该使用List类。但是我建议重命名你的表,因为 Dart 已经有一个List类。

文档中,您可以看到Todosgetter 带有一个Todo(单数)类:

// 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();
  }
}
于 2020-01-14T11:17:46.220 回答