The code flow stops moving forward when it encounters the assignment statement. it doesn’t show any any error nor does the code exit,it just stops there. it works fine on flutter web though
Future<(double, Map<DateTime, int>)> suppliercalc() async {
final user = FirebaseAuth.instance.currentUser;
final orderef = FirebaseFirestore.instance.collection('orders');
final date = DateTime.now();
double monthlysales = 0;
final thismonth = DateTime(date.year, date.month, 1, 0, 0, 0);
final Map<DateTime, int> linegraphdata = {};
final userid = "/userdetails/${user!.uid}";
final docs = await orderef
.where('timestamp', isGreaterThan: thismonth)
.where('supplier_id', isEqualTo: userid)
.where('delivered', isEqualTo: true)
.get();
final docdata = docs.docs;
for (var eachdoc in docdata) {
Timestamp stamp = eachdoc['timestamp'];
DateTime eachdate = stamp.toDate();
eachdate = DateTime(eachdate.year, eachdate.month, eachdate.day);
monthlysales = monthlysales + eachdoc['total'];
if (eachdate.isBefore(DateTime(date.year, date.month, date.day))) {
DateTime edate = DateTime(eachdate.year, eachdate.month, eachdate.day);
if (linegraphdata.containsKey(edate)) {
linegraphdata[edate] =
linegraphdata[edate]! + eachdoc['total'] as int;
} else {
log('before');
linegraphdata[edate] = eachdoc['total'] as int;
log('after');
}
}
}
return (monthlysales, linegraphdata);
}
what this code does is to create a map with each date having the sum of the ‘total’,
but the code stops after showing the first log(‘before’)
i also tried using the addEntries() and putifAbsent() but they too paused at that point
1