════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following NoSuchMethodError was thrown building Builder(dirty): The method '>=' was called on null. Receiver: null Tried calling: >=(25)
The relevant error-causing widget was: MaterialApp file:///C:/Users/Ahmed/AndroidStudioProjects/bmi_calc/lib/main.dart:8:12 When the exception was thrown, this was the stack:
0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
1 calculator.getresult (package:bmicalc/calculator.dart:14:14)
2 _InputPageState.build.. (package:bmicalc/input_page.dart:226:97)
3 MaterialPageRoute.buildPage (package:flutter/src/material/page.dart:87:27)
4 _ModalScopeState.build. (package:flutter/src/widgets/routes.dart:710:43)
At #1 my code is
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';
}
}
}
At #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())));
},)`