I am fairly new to flutter. I am using Getx for state management.What is the best way to listen to firestore realtime updates? I use the RxListin an obx in the ui to build items using a listviewBuilder.
RxList<PayClientModel> payments = <PayClientModel>[].obs;
RxList<ReceiveModel> receipts = <ReceiveModel>[].obs;
RxList<ExpenseModel> expenses = <ExpenseModel>[].obs;
final withdrawalList = <WithdrawModel>[];
RxList<WithdrawModel> withdrawals = <WithdrawModel>[].obs;
FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection('transactions')
.snapshots()
.listen((querySnapshot) {
// expenses.clear();
payments.clear();
receipts.clear();
withdrawals.clear();
for (var doc in querySnapshot.docs) {
final transactionType = doc.data()['transactionType'];
if (doc.exists && transactionType == 'expense') {
expenses.add(ExpenseModel.fromJson(doc.data()));
print(expenses.length);
} else if (transactionType == 'payment') {
payments.add(PayClientModel.fromJson(doc.data()));
} else if (transactionType == 'receipt') {
receipts.add(ReceiveModel.fromJson(doc.data()));
} else if (transactionType == 'withdraw') {
withdrawals.add(WithdrawModel.fromJson(doc.data()));
}
}
I am fairly new to flutter. I am using Getx for state management.What is the best way to listen to firestore realtime updates? I use the RxListin an obx in the ui to build items using a listviewBuilder.
RxList<PayClientModel> payments = <PayClientModel>[].obs;
RxList<ReceiveModel> receipts = <ReceiveModel>[].obs;
RxList<ExpenseModel> expenses = <ExpenseModel>[].obs;
final withdrawalList = <WithdrawModel>[];
RxList<WithdrawModel> withdrawals = <WithdrawModel>[].obs;
FirebaseFirestore.instance
.collection('Users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.collection('transactions')
.snapshots()
.listen((querySnapshot) {
// expenses.clear();
payments.clear();
receipts.clear();
withdrawals.clear();
for (var doc in querySnapshot.docs) {
final transactionType = doc.data()['transactionType'];
if (doc.exists && transactionType == 'expense') {
expenses.add(ExpenseModel.fromJson(doc.data()));
print(expenses.length);
} else if (transactionType == 'payment') {
payments.add(PayClientModel.fromJson(doc.data()));
} else if (transactionType == 'receipt') {
receipts.add(ReceiveModel.fromJson(doc.data()));
} else if (transactionType == 'withdraw') {
withdrawals.add(WithdrawModel.fromJson(doc.data()));
}
}
Share
Improve this question
edited yesterday
Frank van Puffelen
599k85 gold badges888 silver badges858 bronze badges
Recognized by Google Cloud Collective
asked yesterday
Abdirahman AbdullahiAbdirahman Abdullahi
11 bronze badge
2 Answers
Reset to default 0Need assistance with a continuous bugging of something similar to this. I have noticed this trend of things missing and popping back into phone. I have restored with apple almost 4 times this year (today would be #4). I came across emoticon and pho cloud malware information very similar to of reading of these analytics. Please lmk how to get rid of enter image description here
[]helo1
class HomeController extends GetxController {
var count = 0.obs;
void increment() => count++;
}
class HomePage extends StatelessWidget {
final controller = Get.put(HomeController());
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Obx(() => Text("${controller.count}"))),
floatingActionButton: FloatingActionButton(
onPressed: controller.increment),
);
}
}