Home > Mobile >  The method '>=' was called on null. Receiver: null
The method '>=' was called on null. Receiver: null

Time:04-02

So, I figured out that the mistake producing the error is the double _bmi inside the calculateBMI() method. However, I would like to know why including double produces this error? What is the logical process?

import 'dart:math';

class CalculatorBrain {
  CalculatorBrain({this.height, this.weight});

  final int height;
  final int weight;
  double _bmi;

  String calculateBMI() {
    double _bmi = height / pow(height / 100, 2);
    return _bmi.toStringAsFixed(1);
  }

  String getResult() {
    if (_bmi >= 25.0) {
      return 'Overweight';
    } else if (_bmi > 18.5) {
      return 'Normal';
    } else {
      return 'Underweight';
    }
  }

}

CodePudding user response:

Fron the calculateBMI() function, you have redeclared the _bmi variable double _bmi = height / pow(height / 100, 2);. It's supposed to be:

_bmi = height / pow(height / 100, 2);
  • Related