getAllTrackedDonationsForFeedGraph method

Future<List<GraphFeedsDataPoint>> getAllTrackedDonationsForFeedGraph ()

Retrieves all tracked donations and convert them to a list of GraphFeedsDataPoint objects. These will be used to plot the donation data on the feeds graph

Implementation

Future<List<GraphFeedsDataPoint>> getAllTrackedDonationsForFeedGraph() async {
  await openMMDatabase();
  double total = 0;
  List<Map> maps = await db.query(tableTrackedDonations,
    columns: [columnId, columnDateString, columnAmount, columnDonationProcessed],);

  List<GraphFeedsDataPoint> dataPoints = List<GraphFeedsDataPoint>();

  maps.forEach((element) {
    TrackedDonation tracked = TrackedDonation.fromMap(element);
    dataPoints.add(GraphFeedsDataPoint(amount: double.parse((tracked.amount/50).toStringAsFixed(2)), date: tracked.dateRecorded));
  });
  dataPoints.sort((a,b) => a.date.compareTo(b.date));
  for(int i=0; i < dataPoints.length; i++){
    total += dataPoints[i].amount;
    dataPoints[i].amount = total;
  }
  return dataPoints;
}