I have an list of string in List. But I want to count it and display it in the text. How can I achieve that?
StreamBuilder<DocumentSnapshot?>(
stream: FirebaseFirestore.instance
.collection("groups")
.doc(groupId)
.snapshots(),
builder: (context, snapshot) {
//Get a snapShot
var countRoom = snapshot.data?['room'];
//Display a counted room
return Text(countRoom)
)
}
2
Answers
If I correctly understand your question, you need to use the
length
property as follows:If you want to count the unique elements in the List, see this SO answer.
If you want
sum
of the string in your list you can do this: