getWeightLog method

Future<List<WeightData>> getWeightLog({
  1. required DateTime? startDate,
  2. required DateTime? endDate,
  3. WeightUnits? weightUnits = WeightUnits.kg,
  4. int pageNumber = 1,
  5. int itemsPerPage = 7,
})

get user's wight logs

Implementation

Future<List<WeightData>> getWeightLog(
    {required DateTime? startDate,
    required DateTime? endDate,
    WeightUnits? weightUnits = WeightUnits.kg,
    int pageNumber = 1,
    int itemsPerPage = 7}) async {
  List<WeightData> weightDataListData = [];

  List<UserLogReportData> usersLogDataList = await getSymptomsLogReport(
      startDate: startDate,
      endDate: endDate,
      isRequiredPagination: true,
      itemsPerPage: itemsPerPage,
      pageNumber: pageNumber);
  for (int i = 0; i < usersLogDataList.length; i++) {
    WeightData weightData = WeightData();
    UserLogReportData logReportData = usersLogDataList[i];
    double weightValue = double.parse(logReportData.weight!);
    if (logReportData.weightUnit!.isNotEmpty && weightValue > 0) {
      //printMenstrualCycleLogs(
      //    "logReportData.waterValue ${logReportData.waterValue}");

      double weightValue = double.parse(logReportData.weight!);

      // printLogs("logReportData.waterUnit ${logReportData.waterUnit}");
      double weight = 0.0;
      if (logReportData.weightUnit == weightUnits.toString()) {
        weight = weightValue;
      } else {
        if (logReportData.weightUnit == WeightUnits.kg.toString()) {
          weight = convertLbToKg(weightValue);
        } else if (logReportData.weightUnit == WeightUnits.lb.toString()) {
          weight = convertKgToLb(weightValue);
        }
      }
      //printLogs("weight =====$weight");
      weightData.weightValue = weight;
      weightData.dateTime =
          CalenderDateUtils.graphDateFormat(logReportData.logDate!);
      weightData.weightUnit = weightUnits.toString();

      weightDataListData.add(weightData);
    }
  }
  //  printLogs("waterDataListData ${waterDataListData.length}");
  return weightDataListData;
}