Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes after adding age , gender and gender check functionality #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions lib/calculator_brain.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,62 @@
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);
return _bmi.toStringAsFixed(1);
}

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

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.';
Expand Down
45 changes: 28 additions & 17 deletions lib/screens/input_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,36 @@ class _InputPageState extends State<InputPage> {
),
),
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);

},
)
],
),
);
}
}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down