My goal is to query Firebase and return a stream that automatically updates in case is added to the collection that fulfils the where()
statement.
Stream<User> getUsers(String storeLocation) async* {
Stream<QuerySnapshot<User?>> users = _firestore
.collection(firebase_constants.kUsersCollection)
.where('storeLocation', isEqualTo: storeLocation)
.snapshots()
.map((QuerySnapshot<Object?> querySnapshot) {
return querySnapshot.docs.map((QueryDocumentSnapshot<Object?> doc) {
return User.fromJson(doc.data()! as Map<String, dynamic>);
}).toList();
}).expand((users) => users);
}
The User class has a vanilla fromJson
. The error that I have now
error: The return type 'List<User>' isn't a 'Iterable<QuerySnapshot<User?>>', as required by the closure's context. (return_of_invalid_type_from_closure at [firebase_data_repository] lib/src/user_repository.dart:45)
I could simply change the signature, but that wouldn't provide me with a stream.
Thanks for any help.