0

I tried running my app and am getting this error message.

The method '<' was called on null. Receiver: null Tried calling: <(18.5)

The relevant error-causing widget was:

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 ...

This is my code:

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;
}
Benjamin
  • 5,783
  • 4
  • 25
  • 49
  • 1
    Hi, Victor! Where is the BMI variable defined for the `getBMI` function? Your error is on this line, probably: `if (BMI < 18.5) {` – George Jan 05 '20 at 17:33
  • Seem like BMI is not defined as double – hoangquyy Jan 06 '20 at 07:30
  • 1
    Does this answer your question? [What is a NoSuchMethod error and how do I fix it?](https://stackoverflow.com/questions/64049102/what-is-a-nosuchmethod-error-and-how-do-i-fix-it) – nvoigt Nov 23 '20 at 14:23

0 Answers0