import 'package:cloud_firestore/cloud_firestore.dart';
Future<List<Map<String, dynamic>>> getMessages() async {
try {
QuerySnapshot<Map<String, dynamic>> querySnapshot;
if (userType == 'donor') {
querySnapshot = await FirebaseFirestore.instance
.collection('messages')
.where('sender_id', isEqualTo: localid)
.where('receiver_id', isEqualTo: global_id)
.orderBy('time', descending: true)
.get();
} else if (userType == 'taker') {
querySnapshot = await FirebaseFirestore.instance
.collection('messages')
.where('receiver_id', isEqualTo: localid)
.where('sender_id', isEqualTo: taker_id)
.orderBy('time', descending: true)
.get();
} else {
throw Exception('Invalid user type');
}
List<Map<String, dynamic>> messages = querySnapshot.docs
.map((doc) => doc.data())
.toList();
return messages;
} catch (e) {
print(e.toString());
return [];
}
}
I want to fix this problem and want to best solution for this provlem.By focusing on these aspects, you can create a robust solution that converts Firestore data into a usable format for your Flutter application, ensuring both performance and user satisfaction.
New contributor
Nouman Saeed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.