My code is as follows:
Future<String> addPlayersToTable() async {
var userName = await getUserName();
userName = userName.toString();
String uid = getUid();
var photoUrl = await getPhotoUrl();
photoUrl = photoUrl.toString();
await _firestore.collection('public_tables').doc().set({'test': 'test'});
await _firestore
.collection('public_tables')
.doc()
.collection('players')
.doc(uid)
.set({
'username': userName,
'photoUrl': photoUrl,
'uid': uid,
'currentPlayer': false
});
var count = await countTablePlayers();
print(count);
return count;
}
Future countTablePlayers() async {
var allDocs = await _firestore.collection('public_tables').get();
var docId = allDocs.docs.last.id;
var count = await _firestore
.collection('public_tables')
.doc(docId)
.collection('players')
.count()
.get();
return count.toString();
}
I am looking to get a actual string value instead of AggregateQuerySnapshot. Can someone please help me out? Thank you so much in advance.
Regards,
Matt
I am looking to get a actual string value instead of AggregateQuerySnapshot. Can someone please help me out? Thank you so much in advance.
Regards,
Matt
I am looking to get a actual string value instead of AggregateQuerySnapshot. Can someone please help me out? Thank you so much in advance.
Regards,
Matt
2
Answers
My edited code is as below:
I am getting another error: bad state, no element. The first document in firebase is also in Italics. Apparently its showing as null. How can I fix this?
From the documentation on getting the count in Flutter:
So you need to call
count.count
rather thancount.toString()
.