calculateBMR method
Future<double>
calculateBMR({
- required double weight,
- required double height,
- required int age,
- required bool isMale,
- required double bodyFatPercentage,
- Ethnicity ethnicity = Ethnicity.white,
override
Implementation
@override
Future<double> calculateBMR({
required double weight,
required double height,
required int age,
required bool isMale,
required double bodyFatPercentage,
Ethnicity ethnicity = Ethnicity.white,
}) async {
// Validate inputs
if (weight <= 0 ||
height <= 0 ||
age <= 0 ||
bodyFatPercentage < 0 ||
bodyFatPercentage > 100) {
throw ArgumentError("Invalid input values.");
}
double bmi =
BodyMassIndex.calculateKiloAndMeters(weight: weight, height: height);
double fatFreeMass = weight * (1 - bodyFatPercentage / 100);
if (age >= 60) {
return _calculateCunningham(fatFreeMass);
}
double bmr = _calculateMifflinStJeor(weight, height, age, isMale);
switch (ethnicity) {
case Ethnicity.black:
bmr = _calculateOwen(weight, isMale);
break;
case Ethnicity.asian:
bmr = _calculateHenry(weight, height, age, isMale);
break;
case Ethnicity.hispanic:
bmr *= 1.05; // Simple adjustment factor
break;
case Ethnicity.white:
case Ethnicity.other:
default:
break;
}
if (bmi < 18.5) {
bmr = _calculateOwen(weight, isMale);
} else if (bmi >= 30) {
bmr = _calculateMuller(weight, height, age, isMale);
}
return Future.value(bmr);
}