Trouble reading data in Firestore

Asked

Viewed 61 times

0

I’m trying to build an app with Flutter using Firestore as a database. I’m having trouble locating a document’s undercutting. I’m having trouble recovering the data, at the end of the list function I need it to wait for the listCanecas before returning, I tried to put await in several places but it didn’t work I’m using Mobx:

@override
  Stream<List<Botijao>> list() {
    listCanecas = [];
    return firestore
        .doc(this.doc.path)
        .collection("botijoes")
        .snapshots()
        .map((query) {
      return query.docs.map((doc) {
        doc.reference.collection('canecas').snapshots().listen((getCanecas));
        return Botijao.fromMap(doc, listCanecas);
      }).toList();
    });
  }
  
  getCanecas(QuerySnapshot snapshot) async {
    for (var doc in snapshot.docs) {
      getRacks(doc).listen((racks) {
        listCanecas.add(Caneca.fromMap(doc.reference, racks));
      });
    }
  }

  Stream<List<Rack>> getRacks(DocumentSnapshot doc) {
    return firestore
        .doc(doc.reference.path)
        .collection("racks")
        .snapshots()
        .map((query) {
      return query.docs.map((docR) {
        return Rack.fromMap(docR);
      }).toList();
    });
  }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.