This is the getUserId and my function to count data that required the userId:
String get getuserId => AuthService.firebase().currentUser!.id;
Future<AggregateQuerySnapshot> myCollectionPrayer({required String userId}) =>
FirebaseFirestore.instance
.collection('record_prayer')
.where('dailyPrayerStatus', isEqualTo: 'Prayed On Time')
.count()
.get();
This is where I'm using the FutureBuilder
`<AggregateQuerySnapshot>`:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Count Firebase Documents'),
),
body: FutureBuilder<AggregateQuerySnapshot>(
future: myCollectionPrayer(userId: getuserId),
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Text('oops');
}
if (snapshot.connectionState == ConnectionState.done) {
int docCount = snapshot.data!.count;
return Text(
docCount.toString(),
style: Theme.of(context).textTheme.displayLarge,
);
}
return const CircularProgressIndicator();
},
),
There is no error on the code, but the display count for all user recorded data.
this my screenshot for firebase