Users make a post, say ADS post. Different users interact with the post by sending requests. I'm using different emulators to check this.
When I use an emulator for user A to access an ADS post and sends a requests, the device(emulator A) displays the ADS posts to which the user A has sent the request to.
However, when I use a different divice(emulator B) for user B to access an ADS post, (even when the post is not the same as the post accessed by user A), the emulator displays the ADS post to which the user has send the request, but then the emulator A no longer displays the ADS posts to which user A has sent the request.
I tried a lot of emulators and the same thing is happening. Any solution?
My code for accessing the requests of a user.
QueryDocumentSnapshot<Map<String, dynamic>>? selectedRide;
DateTime dateTime = DateTime.now();
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
// final screenHeight = MediaQuery.of(context).size.height;
return StreamBuilder<QuerySnapshot<Map<String, dynamic>>>(
stream:
FirebaseFirestore.instance.collectionGroup('Requests').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
scrollDirection: Axis.vertical,
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
final request = snapshot.data!;
String currentID = request.docs[index].get('UID');
if (currentID == FirebaseAuth.instance.currentUser!.uid) {
return Card(
child: ListTile(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MyRidesPageScreen(
selectedRide: selectedRide,
)));
setState(() {
selectedRide = snapshot.data!.docs[index];
});
},
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: screenWidth * 0.15,
child: Text(
snapshot.data!.docs[index].get('Departure date'),
style: const TextStyle(color: Colors.blue),
),
),
SizedBox(
width: screenWidth * 0.2,
child: Text(snapshot.data!.docs[index]
.get('Departure city')),
),
SizedBox(
width: screenWidth * 0.1,
child: const Text('-'),
),
SizedBox(
width: screenWidth * 0.2,
child: Text(
snapshot.data!.docs[index].get('Arrival city')),
),
SizedBox(
width: screenWidth * 0.15,
child: Text(
snapshot.data!.docs[index].get('Departure time'),
style: const TextStyle(color: Colors.blue),
),
),
],
),
),
);
}
return null;
});
}
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (!snapshot.hasData) {
return const Center(
child: SizedBox(
child: Text('You have not made any requests yet'),
),
);
}
return const Center(child: CircularProgressIndicator());
},
);
}