Skip to content

Commit

Permalink
Merge pull request #10 from RisabhKedai/main
Browse files Browse the repository at this point in the history
Added new features and resolved some bugs
  • Loading branch information
Rupesh-1901 authored Oct 18, 2021
2 parents 05895c7 + f1e3a49 commit 3c4ab5b
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 30 deletions.
Binary file added bmi-calculator-flutter-master/assets/ok.webp
Binary file not shown.
Binary file not shown.
Binary file added bmi-calculator-flutter-master/assets/worry.webp
Binary file not shown.
22 changes: 15 additions & 7 deletions bmi-calculator-flutter-master/lib/calculator_brain.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import 'dart:math';

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

final int height;
final int weight;
final height;
final weight;
double _bmi;

String calculatorBMI() {
_bmi = weight / pow((height / 100), 2);
//_bmi.toStringAsFixed(1);
Expand All @@ -17,11 +15,11 @@ class CalculatorBrain {

String getResult() {
if (_bmi >= 25) {
return "overweight";
return "OVERWEIGHT";
} else if (_bmi >= 18.5) {
return "normal";
return "NORMAL";
} else {
return "underweight";
return "UNDERWEIGHT";
}
}

Expand All @@ -34,4 +32,14 @@ class CalculatorBrain {
return "Thoda sa sarir pe bhi dhyan dedo";
}
}

String getAnimation() {
if (_bmi >= 25) {
return "assets/skeleton.webp";
} else if (_bmi >= 18.5) {
return "assets/ok.webp";
} else {
return "assets/worry.webp";
}
}
}
74 changes: 60 additions & 14 deletions bmi-calculator-flutter-master/lib/input_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//import 'dart:html';
import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -26,6 +26,7 @@ class _InputPageState extends State<InputPage> {
int height = 180;
int weight = 60;
int age = 19;
bool inch_or_cm = false;
// Color maleCardColor = inactiveCardColor;
// Color femaleCardColor = inactiveCardColor;
// void updateColor(Gender selectedGender) {
Expand Down Expand Up @@ -97,28 +98,52 @@ class _InputPageState extends State<InputPage> {
),
Expanded(
child: ReUsuable(
onPress: () {
setState(() {
inch_or_cm = !inch_or_cm;
});
},
colour: kActiveCardColor,
cardChild: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"height",
"HEIGHT",
style: kLabelTextStyle,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: <Widget>[
Text(
height.toString(),
style: kNumberTextStyle,
),
Text(
"cm",
style: kLabelTextStyle,
)
],
children: (inch_or_cm)
? <Widget>[
Text(
height.toString(),
style: kNumberTextStyle,
),
Text(
"cm",
style: kLabelTextStyle,
)
]
: <Widget>[
Text(
((height * 0.394).round() ~/ 12).toString(),
style: kNumberTextStyle,
),
Text(
"ft ",
style: kLabelTextStyle,
),
Text(
((height * 0.394).round() % 12).toString(),
style: kNumberTextStyle,
),
Text(
"inch",
style: kLabelTextStyle,
)
],
),
SliderTheme(
data: SliderTheme.of(context).copyWith(
Expand Down Expand Up @@ -169,7 +194,12 @@ class _InputPageState extends State<InputPage> {
icon: FontAwesomeIcons.minus,
onPressed: () {
setState(() {
weight--;
weight = max(weight - 1, 0);
});
},
onLongPressed: () {
setState(() {
weight = max(weight - 1, 0);
});
},
),
Expand All @@ -181,6 +211,11 @@ class _InputPageState extends State<InputPage> {
weight++;
});
},
onLongPressed: () {
setState(() {
weight++;
});
},
),
],
),
Expand Down Expand Up @@ -209,7 +244,12 @@ class _InputPageState extends State<InputPage> {
icon: FontAwesomeIcons.minus,
onPressed: () {
setState(() {
age--;
age = max(age - 1, 0);
});
},
onLongPressed: () {
setState(() {
age = max(age - 1, 0);
});
},
),
Expand All @@ -221,6 +261,11 @@ class _InputPageState extends State<InputPage> {
age++;
});
},
onLongPressed: () {
setState(() {
age++;
});
},
),
],
),
Expand All @@ -244,6 +289,7 @@ class _InputPageState extends State<InputPage> {
bmiResult: calc.calculatorBMI(),
resultText: calc.getResult(),
interpretation: calc.getInterpretation(),
animation: calc.getAnimation(),
)),
);
},
Expand Down
9 changes: 8 additions & 1 deletion bmi-calculator-flutter-master/lib/results_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class ResultsPage extends StatelessWidget {
ResultsPage(
{@required this.bmiResult,
@required this.resultText,
@required this.interpretation});
@required this.interpretation,
@required this.animation});
final String bmiResult;
final String resultText;
final String interpretation;
final String animation;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -44,6 +46,11 @@ class ResultsPage extends StatelessWidget {
resultText,
style: kResultTextStyle,
),
Image(
image: AssetImage(animation),
width: MediaQuery.of(context).size.width / 5,
height: MediaQuery.of(context).size.height / 5,
),
Text(
bmiResult,
style: kBMITextStyle,
Expand Down
1 change: 1 addition & 0 deletions bmi-calculator-flutter-master/lib/reusable_card.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import 'package:flutter/material.dart';

class ReUsuable extends StatelessWidget {
Expand Down
58 changes: 50 additions & 8 deletions bmi-calculator-flutter-master/lib/round_icon_button.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,60 @@
import 'package:flutter/material.dart';

class RoundIconButton extends StatelessWidget {
RoundIconButton({@required this.icon, this.onPressed});
class RoundIconButton extends StatefulWidget {
final IconData icon;
final Function onPressed;
final Function onLongPressed;
RoundIconButton({@required this.icon, this.onPressed, this.onLongPressed});
_RoundIconButton createState() =>
_RoundIconButton(this.icon, this.onPressed, this.onLongPressed);
}

class _RoundIconButton extends State<RoundIconButton> {
final IconData icon;
final Function onPressed;
final Function onLongPressed;
_RoundIconButton(this.icon, this.onPressed, this.onLongPressed);

bool isPressed = false;
@override
Widget build(BuildContext context) {
return RawMaterialButton(
child: Icon(icon),
onPressed: onPressed,
elevation: 6.0,
return Container(
constraints: BoxConstraints.tightFor(width: 56.0, height: 56.0),
shape: CircleBorder(),
fillColor: Colors.grey,
child: GestureDetector(
child: ElevatedButton(
child: Icon(icon),
onPressed: onPressed,
style: ButtonStyle(
elevation: MaterialStateProperty.resolveWith<double>(
(Set<MaterialState> states) {
return 6.0;
},
),
overlayColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
return Colors.transparent;
}),
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
return Colors.grey;
},
),
shape: MaterialStateProperty.resolveWith<OutlinedBorder>(
(Set<MaterialState> states) {
return CircleBorder();
},
),
),
),
onLongPressStart: (_) async {
isPressed = true;
do {
if (onLongPressed != null) onLongPressed();
await Future.delayed(Duration(milliseconds: 50));
} while (isPressed);
},
onLongPressEnd: (_) => setState(() => isPressed = false),
),
);
}
}
4 changes: 4 additions & 0 deletions bmi-calculator-flutter-master/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ dev_dependencies:

flutter:
uses-material-design: true
assets:
- assets/skeleton.webp
- assets/ok.webp
- assets/worry.webp

0 comments on commit 3c4ab5b

Please sign in to comment.