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()
.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 getting the error, bad state no elements. The first document in firebase is in Italics and apparently seems to be null when I read it. How can I fix it? Please advise.