diff --git a/lib/calculator_brain.dart b/lib/calculator_brain.dart index 5783edd..99dc0e4 100644 --- a/lib/calculator_brain.dart +++ b/lib/calculator_brain.dart @@ -1,12 +1,17 @@ import 'dart:math'; +import 'package:bmi_calculator/screens/input_page.dart'; +import 'package:flutter/cupertino.dart'; class CalculatorBrain { - CalculatorBrain({this.height, this.weight}); - + CalculatorBrain({@required this.weight,@required this.height,@required this.age,@required this.gender}); final int height; final int weight; - + final int age; + final Gender gender; double _bmi; + //start values for 25-34 male + double _overweight = 25.0; + double _underweight = 20; String calculateBMI() { _bmi = weight / pow(height / 100, 2); @@ -14,9 +19,34 @@ class CalculatorBrain { } String getResult() { - if (_bmi >= 25) { + //Gender Check + if (gender == Gender.female) { + _overweight--; + _underweight--; + } + + //Age Check + if (age <= 24) { + _overweight--; + _underweight--; + // 25 -34 is the normal Rate + } else if (age >= 35 && age <= 44) { + _overweight++; + _underweight++; + } else if (age >= 45 && age <= 54) { + _overweight = _overweight + 2; + _underweight = _underweight + 2; + } else if (age >= 55 && age <= 64) { + _overweight = _overweight + 3; + _underweight = _underweight + 3; + } else if (age > 64) { + _overweight = _overweight + 4; + _underweight = _underweight + 4; + } + + if (_bmi >= _overweight) { return 'Overweight'; - } else if (_bmi > 18.5) { + } else if (_bmi > _underweight) { return 'Normal'; } else { return 'Underweight'; @@ -24,9 +54,9 @@ class CalculatorBrain { } String getInterpretation() { - if (_bmi >= 25) { + if (_bmi >= _overweight) { return 'You have a higher than normal body weight. Try to exercise more.'; - } else if (_bmi >= 18.5) { + } else if (_bmi > _underweight) { return 'You have a normal body weight. Good job!'; } else { return 'You have a lower than normal body weight. You can eat a bit more.'; diff --git a/lib/screens/input_page.dart b/lib/screens/input_page.dart index d3da204..25d28d9 100644 --- a/lib/screens/input_page.dart +++ b/lib/screens/input_page.dart @@ -212,25 +212,36 @@ class _InputPageState extends State { ), ), BottomButton( - buttonTitle: 'CALCULATE', - onTap: () { - CalculatorBrain calc = - CalculatorBrain(height: height, weight: weight); + buttonTile: 'CALCULATE', + onTap: () { + if (selectedGender == null){ + Alert( + style: AlertStyle( + backgroundColor: Color(0xFF1D1E33), + titleStyle: kLargeButtonText, - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => ResultsPage( - bmiResult: calc.calculateBMI(), - resultText: calc.getResult(), - interpretation: calc.getInterpretation(), ), - ), - ); - }, - ), - ], - ), + context: context, + title: 'Please select Gender.', + ).show(); + + } + else { + CalculatorBrain calc = CalculatorBrain(height: height, + weight: weight, + age: age, + gender: selectedGender); + + Navigator.push(context, + MaterialPageRoute(builder: (context) => ResultPage(bmiResult: calc.calculateBMI(),resultText: calc.getResult(),interpretation: calc.getInterpretation(),))); + + } + //print(selectedGender); + + }, + ) + ], + ), ); } } diff --git a/pubspec.yaml b/pubspec.yaml index 6dded66..039f113 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,8 @@ dependencies: sdk: flutter cupertino_icons: ^0.1.2 - font_awesome_flutter: ^8.4.0 + font_awesome_flutter: ^9.0.0 + rflutter_alert: ^2.0.2 dev_dependencies: flutter_test: