Answer the question
In order to leave comments, you need to log in
How to get data from firestore (flutter)?
I'm writing my first application on flutter and I'm having trouble learning the backend.
class Content {
int index;
Content({this.index});
Stream<QuerySnapshot> streamCards = FirebaseFirestore.instance
.collection('cards')
.snapshots();
text(){
text(AsyncSnapshot<QuerySnapshot> snapshot) {
if (index > snapshot.data.docs.length - 1) {
index = snapshot.data.docs.length - 1;
return snapshot.data.docs[index]['desc'];
} else {
return snapshot.data.docs[index]['desc'];
}
}
return StreamBuilder(
stream: streamCards,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
return Text('${
text(snapshot)
}');
} else if (snapshot.hasError) {
return Text('error');
} else {
return Text('Loading');
}
}
);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question