getMinMaxWeightLog method
Get min and max wight of current user
Implementation
Future<Map<String, double>> getMinMaxWeightLog(
{WeightUnits? weightUnits = WeightUnits.kg}) async {
final dbHelper = MenstrualCycleDbHelper.instance;
Database? db = await dbHelper.database;
double minValue = 0;
double maxValue = 0;
final mInstance = MenstrualCycleWidget.instance!;
String customerId = mInstance.getCustomerId();
final List<Map<String, dynamic>> queryResponse = await db!.rawQuery(
"Select * from ${MenstrualCycleDbHelper.tableDailyUserSymptomsLogsData} WHERE ${MenstrualCycleDbHelper.columnCustomerId}='$customerId'");
final encryption = Encryption.instance;
List.generate(queryResponse.length, (i) {
String weightUnit = encryption
.decrypt(queryResponse[i][MenstrualCycleDbHelper.columnWeightUnit]);
double weightValue = double.parse(encryption
.decrypt(queryResponse[i][MenstrualCycleDbHelper.columnWeight]));
double weight = 0.0;
if (weightValue > 0) {
if (weightUnit == weightUnits.toString()) {
weight = weightValue;
} else {
if (weightUnit == WeightUnits.kg.toString()) {
weight = convertLbToKg(weightValue);
} else if (weightUnit == WeightUnits.lb.toString()) {
weight = convertKgToLb(weightValue);
}
}
}
if (minValue == 0) {
minValue = weight;
}
if (weight > 0) {
if (minValue >= weight) {
minValue = weight;
}
if (maxValue <= weight) {
maxValue = weight;
}
}
});
return {
'min_value': minValue,
'max_value': maxValue,
};
}