════════ Исключение, обнаруженное библиотекой виджетов ══════════════════════════════════ ═════════════════════ Следующее событие NoSuchMethodError было брошено в здание Builder (грязный): метод '> =' был вызван для нуля. Получатель: null Пробный вызов:> = (25)
Соответствующий виджет, вызывающий ошибки, был: MaterialApp file: /// C: /Users/Ahmed/AndroidStudioProjects/bmi_calc/lib/main.dart: 8:12 Когда возникло исключение, это был стек:
0 Object.noSuchMethod (dart: core-patch / object_patch.dart: 53: 5)
1 calculator.getresult ( пакет: bmicalc / calculator.dart: 14: 14)
2 _InputPageState.build .. (пакет: bmicalc / input_page.dart: 226: 97)
3 MaterialPageRoute.buildPage (пакет: flutter / src / material / page.dart: 87: 27)
4 _ModalScopeState.build. (пакет: flutter / src / widgets / rout.dart: 710: 43)
На # 1 мой код
class calculator {
calculator({this.height, this.weight});
final int height;
final int weight;
double _bmi;
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';
}
return ' ';
}
String getRemarks() {
if (_bmi >= 25) {
return 'Your weight is more than average body weight, try to excercise.';
} else if (_bmi > 18.5) {
return 'Your weight is normal';
} else {
return 'Your weight is less than average body weight, try to eat more';
}
}
}
На # 2
`GestureDetector(
onTap: () {
calculator cal = calculator(height: height, weight: weight);
Navigator.push(context, MaterialPageRoute(builder: (context) => results(result: calculator().getresult(), bmi: calculator().calculatebmi(), remarks: calculator().getRemarks())));
},)`