How to convert `Stream<QuerySnapshot<Map<String, dynamic>>>` to a List?

580

Try:

userList.add(kako.User.fromMap(querySnapshot.docs[i].data() as Map<String, dynamic>))
Share:
580
bricend96
Author by

bricend96

Updated on January 01, 2023

Comments

  • bricend96
    bricend96 over 1 year

    I want to fetch all users except the current user from the Firestore collections, but I've got this error:

    The argument type 'QueryDocumentSnapshot<Object?>' can't be assigned to the parameter type 'Map<String, dynamic>').  
    

    A fragment of my code:

    Future <List<kako.User>> fetchAllUsers(User currentUser) async {
        List<kako.User> userList =  List<kako.User>.generate(20, (index)=>kako.User());
        QuerySnapshot querySnapshot = await fireStore.collection("users").get();
        for (var i = 0; i < querySnapshot.docs.length ; i++) {
            if(querySnapshot.docs[i].id != currentUser.uid){
                userList.add(kako.User.fromMap(querySnapshot.docs[i].data()));
            }
        }
        return userList;
    }
    

    querySnapshot.docs[i].data() is underlined with red