Home > Software design >  The argument type 'Iterable<CloudNote>' can't be assigned to the parameter type
The argument type 'Iterable<CloudNote>' can't be assigned to the parameter type

Time:09-29

Hello guys I need help in this error I tried a lot but nothing is working I am trying to make some notes but because of this error nots are not showing on home screen.

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();
      }
    },
  ),

Please help me in this I will be very thank full.

CodePudding user response:

This error happens whenever you try to pass an Iterable<T> to something that expects a List<T>. Based on your code, there are two possible cases:

  1. Try removing the as Iterable<CloudNote> (and perhaps changing to a List<CloudNote> assuming it is one). Ideally, your StreamBuilder should be typed, like StreamBuilder<List<CloudNote>>.

  2. Change notes: allNotes, to notes: allNotes.toList(),

CodePudding user response:

Change

notes: allNotes

to

notes: allNotes.toList()
  • Related