I have a Firestore structure enter image description here what i want is i want to get count of all the members that are enrolled within a user. But Recursive call to below function is just counting the initial array count.
Future<int> getalldata(String docref) async {
int count = 0, abhj = 0;
DocumentReference docRef =
FirebaseFirestore.instance.collection('memberships').doc(docref);
DocumentSnapshot value = await docRef.get();
print(value.data().toString());
if (value.data().toString().contains('referredto:')) {
print("CHala");
if (value.get('referredto').length > 0) {
print(value.get('referredto').length);
for (dynamic i in value.get('referredto')) {
count += await getalldata(i.id.toString());
}
//print('its empty' + value.get('referredto')[0].id.toString())
} else {
count = await count + 1;
print('ye b1');
}
} else {
count = await count + 1;
print('ye b');
}
print("count>>" + count.toString());
return await count;
}
I want recursive function which can count all the memberships. But i am getting just the count in the initial Call.