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

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';
    }
  }

}


Solution 1:[1]

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);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Athanas KE