【发布时间】:2022-01-05 15:20:41
【问题描述】:
我正在从 sqlite 获取数据并尝试在列表视图中设置它,但出现错误:
type 'Future<List<Note>>' is not a subtype of type 'List<Note>'
这是我的sqlite查询函数:
Future<List<Note>> readAllNotes() async {
final db = await instance.database;
final orderBy = '${NoteFields.timeAdded} ASC';
final result = await db?.query(tableNotes, orderBy: orderBy);
return result!.map((json) => Note.fromJson(json)) as List<Note>;
}
这里是调用 readAllNotes() 的地方:
class NoteListWidget extends StatefulWidget {
const NoteListWidget({
Key? key,
}) : super(key: key);
@override
State<NoteListWidget> createState() => _NoteListWidgetState();
}
class _NoteListWidgetState extends State<NoteListWidget> {
@override
Widget build(BuildContext context) {
List<Note> note = NotesDataBase.instance.readAllNotes() as List<Note>;
return ListView.builder(
itemCount: note.toString().characters.length,
itemBuilder: (ctx, index) {
return NoteTileWidget(
body: note[index].body,
title: note[index].title,
timeAdded:
('${note[index].timeAdded.day}/${note[index].timeAdded.month}/${note[index].timeAdded.year}'),
id: note[index].id,
);
});
} }
【问题讨论】:
标签: android ios flutter dart future