I am having an error with my dart code, which I tried using "?" but still it didn't work.
I am seeing this error message "Non-nullable instance field '_bmi' must be initialized flutter"
import 'dart:math';
class CalculatorBrain {
final height;
final weight;
double _bmi;
CalculatorBrain({
this.height,
this.weight,
});
String calculateBMI() {
_bmi = weight / pow(height / 100, 2);
return _bmi.toStringAsFixed(1);
}
String getResult() {
if (_bmi >= 25) {
return 'overweight';
} else if (_bmi > 18.5) {
return 'Normal';
} else {
return 'underweight';
}
}
String interpretation() {
if (_bmi >= 25) {
return 'you have a higher than normal body weight. try to exercise more';
} else if (_bmi > 18.5) {
return 'you have a normal body weight';
} else {
return 'you have a normal body weight you can eat a little bit more';
}
}
}
How do I fix this?