2
Hello, I build one ListView
with a FutureBuilder
.
But I need to access a sub-collection, then a document and get a field from the document.
But returns null, how do I do that?
For example: To get the field test of the document, I do:
snapshot.data[index].data["test"]
but to enter the sub_collection, Document and obtain the field of test, I can’t do it the normal way (which is used by Hasura)
snapshot.data[index].data["sub_collection"]["document"]["test"]
My code so far
getEstablishments:
Future getEstabelecimentos() async {
var firestore = Firestore.instance;
QuerySnapshot dados =
await firestore.collection("estabelecimentos").getDocuments();
return dados.documents;
}
Futurebuilder:
Container(
child: FutureBuilder(
future: getEstabelecimentos(),
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 15),
Center(
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(
Colors.blue),
),
)
],
);
} else {
return Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30)),
color: Colors.white,
),
child: Column(
children: <Widget>[
Container(
color: Colors.white,
child: ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
print(snapshot.data[index].data["name"]);
print(snapshot.data[index].data["category"]);
return GestureDetector(
child: makeItem(nome: snapshot.data[index], categoria: snapshot.data[index].data["categoria"], checkins: snapshot.data[index].data["sub_colecao"]["documento"]['teste']),
onTap: () => {},
);
}),
),
],
));
}
}),
)