Home > Back-end >  Why is Flutter Navigator not working after adding calculation to onTap?
Why is Flutter Navigator not working after adding calculation to onTap?

Time:09-21

My flutter navigator is not working after I added the bold code below to it. Does anybody know why? When I want to push to the ResultsPage, it does not work after adding the calculation to it.

calculate_button(
            onTap: () {
              **CalculationBrain calculator = CalculationBrain();
              String bmi = calculator.getBMI(weight, height);**
              Navigator.push(
                context,
                MaterialPageRoute(builder: (context) => ResultsPage(bmi)),
              );
            },
class ResultsPage extends StatelessWidget {
  **ResultsPage (this.bmi);
  String bmi;**
``

 String getBMI (weight, height) {
   String bmi = weight/pow(height/100, 2).toStringAsFixed(1);
   return bmi;
  }

``

CodePudding user response:

If you give your parameters a double type and put parentheses around your calculation, this should work

String getBMI(double weight, double height) {
    String bmi = (weight / pow(height / 100, 2)).toStringAsFixed(1);
    return bmi;
  }
  • Related