参数类型'Iterable<CloudNote>'不能分配给参数类型"列表<CloudNote>"



大家好,我在这个错误中需要帮助。我尝试了很多,但都不起作用。我正在尝试做一些笔记,但由于这个错误,主屏幕上没有显示nots。

body: StreamBuilder(
stream: _notesService.allNotes(ownerUserId: userId),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
case ConnectionState.active:
if (snapshot.hasData) {
final allNotes = snapshot.data as Iterable<CloudNote>;
return NotesListView(
notes: allNotes,
onDeleteNote: (note) async {
await _notesService.deleteNote(documentId: note.documentId);
},
onTap: (note) {
Navigator.of(context).pushNamed(
createOrUpdateNoteRoute,
arguments: note,
);
},
);
} else {
return const CircularProgressIndicator();
}
default:
return const CircularProgressIndicator();
}
},
),

请在这方面帮助我,我将非常感谢。

每当您试图将Iterable<T>传递给需要List<T>的对象时,就会发生此错误。根据您的代码,有两种可能的情况:

  1. 尝试删除as Iterable<CloudNote>(并可能更改为List<CloudNote>,假设它是一个(。理想情况下,应该键入StreamBuilder,如StreamBuilder<List<CloudNote>>

  2. notes: allNotes,更改为notes: allNotes.toList(),

更改

notes: allNotes

notes: allNotes.toList()

相关内容

最新更新