Jabli
Jabli

Reputation: 41

Select multiple fields from firebase

Im trying to get EventDay and taskName from database where userEmail is equal to parameter userEmail, but i manage to get only EventDay. Shoul i use different query to get multiple fields?

class DatabaseService{
  final CollectionReference userAssignments =
  Firestore.instance.collection('userAssignments');

  Future<void> getEventsOfUser(String email) async {

    //We look for user with email that was passed when we call function

    return userAssignments.where("email", isEqualTo: email).snapshots().listen(
    (data) =>
        data.documents.forEach((doc) => userEventDay = doc["eventDay"]));
   }
}

This is document for one of the emails

Upvotes: 0

Views: 376

Answers (1)

Instead of using the fat arrow notation, use curly bracket and write another line of code to get the taskName and all the other fields you might need.

here is an example for this

Future<void> getEventsOfUser(String email) async {
return userAssignments.where("email", isEqualTo: email).snapshots().listen(
(data) =>
    data.documents.forEach((doc) {
    userEventDay = doc["eventDay"];
    taskName  = doc["eventDay"];
    } ));

}

Upvotes: 1

Related Questions