Home > Software design >  type 'Future<List<Iterable<Book>>>' is not a subtype of type 'Strea
type 'Future<List<Iterable<Book>>>' is not a subtype of type 'Strea

Time:01-10

im getting that error , can you help?

class BooksViewModel extends ChangeNotifier {

Database _database = Database();

Stream<List> getBookList() { const String booksRef = "books";

///stream<QuerySnapshot> --> Stream<List><DocumentSnapshot>>
Stream<List<DocumentSnapshot>> streamListDocument = _database
    .getBookListFromApi(booksRef)
    .map((querySnapshot) => querySnapshot.docs);

/// Stream<List><DocumentSnapshot> --> Stream<List><Book>

Stream<List<Book>> streamListBook = streamListDocument
    .map((listOfDocSnap) => listOfDocSnap.map(
        (docSnap) => Book.fromMap(docSnap.data() as Map<String, dynamic>)))
    .toList() as Stream<List<Book>>;

return streamListBook;

} }

CodePudding user response:

I think you meant to call .toList() after the inner .map rather than the outer .map. The following code just moves the closing paren to after the .toList():

Stream<List<Book>> streamListBook = streamListDocument
    .map((listOfDocSnap) => listOfDocSnap.map(
        (docSnap) => Book.fromMap(docSnap.data() as Map<String, dynamic>))
    .toList()) as Stream<List<Book>>; 
  •  Tags:  
  • Related