我尝试运行我的应用程序,并收到此错误消息。
方法'<'在null上被调用。接收方:null尝试调用: <(18.5)
相关的引起错误的小部件是:
MaterialApp lib\main.dart:11 When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1 CalculateBMI.getBMI package:health_calculator/bmi_calc.dart:11
#2 _ThirdScreenState.build.<anonymous closure>.<anonymous closure> package:health_calculator/third_screen.dart:175
#3 MaterialPageRoute.buildPage package:flutter/…/material/page.dart:87
#4 _ModalScopeState.build.<anonymous closure> package:flutter/…/widgets/routes.dart:710 ...
这是我的代码:
String getBMI() {
if (BMI < 18.5) {
return 'Underweight';
} else if (BMI >= 18.5 || BMI <= 24.9) {
return 'Healthy Weight';
} else if (BMI >= 25.0 || BMI <= 29.9) {
return 'Overweight';
} else {
return 'Obese';
}
}
String getRange() {
var BMI = weight / pow(height / 100, 2);
if (BMI < 18.5) {
return '(BMI less than 18.5)';
} else if (BMI >= 18.5 || BMI <= 24.9) {
return '(BMI 18.5 to 24.9)';
} else if (BMI >= 25.0 || BMI <= 29.9) {
return '(BMI 25 to 30)';
} else {
return '(BMI 30+)';
}
}
returnBMI() {
BMI = weight / pow(height / 100, 2);
return BMI;
}