The view i have for my dashboard is here https://postimg.cc/PvjfLfWf. I want to pass a date from UI to controller and fetch orders for that date. Seperate them into delivered orders and others. After that i want to display length of delivered orders and ongoing orders. Also i want to display total amount of orders placed via COD. and display COD orders in summary widget.
I have written code in UI. But it's taking too much of time to load since it is a large database. How to do this in GetX controller?
processOrders() {
_db
.collection('orders')
.where('driverId', isEqualTo: sp.getString('uid'))
.where(
'timeStamp', isGreaterThanOrEqualTo: Timestamp.fromDate(pickedDate!))
.where('timeStamp', isLessThan: Timestamp.fromDate(nextDay!))
.where('status', isEqualTo: 'Delivered')
.orderBy('timeStamp', descending: true)
.get()
.then((querySnapshot) {
querySnapshot.docs.forEach((element) {
deliveredOrders.add(element.data());
});
});
var CODOrders = deliveredOrders.where((element) =>
element['paid'] == 'COD').toList();
CODOrders.forEach((element) {
cashInHand = cashInHand element['grandTotal'];
tip = tip element['tip'];
});
}
I'm new to GETX and flutter. Any help would be appreciated.
CodePudding user response:
example if you want to display the "totalAmount"
declare variable and assign the value in controller homeController.dart
var totalAmount = 0.00.obs;
// assign data
totalAmount.value = 1000;
home.dart
final homeController _homeController = Get.put(homeController());
// read data here like this
Text(_homeController.totalAmount.value)