mirror of
https://github.com/rjNemo/bmi_calculator_app
synced 2026-06-06 02:16:41 +00:00
feat: result page
This commit is contained in:
parent
533f410bfc
commit
43868f7d93
5 changed files with 153 additions and 26 deletions
10
.vscode/settings.json
vendored
Normal file
10
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"spellright.language": [
|
||||
"en"
|
||||
],
|
||||
"spellright.documentTypes": [
|
||||
"markdown",
|
||||
"latex",
|
||||
"plaintext"
|
||||
]
|
||||
}
|
||||
|
|
@ -11,7 +11,9 @@ Compute and track your Body Mass Index and Body Fat Percentage
|
|||
- [ ] bmi over 40 : red - morbid obesity
|
||||
- [ ] bmi tracker: date, value, graph
|
||||
- [ ] profile: save age, height, genre, local storage
|
||||
- [ ] bmi on second screen
|
||||
- [x] bmi on second screen
|
||||
- [ ] feedback on genre select
|
||||
|
||||
* [doc](https://www.santepratique.fr/nutrition/calcul-imc)
|
||||
|
||||
- [design inspiration](https://dribbble.com/shots/13913052-DailyUI-004-Calculator)
|
||||
|
|
|
|||
|
|
@ -1,22 +1,32 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'result.dart';
|
||||
|
||||
class CalculatorPage extends StatefulWidget {
|
||||
CalculatorPage({Key? key}) : super(key: key);
|
||||
final String title = 'BMI Calculator';
|
||||
static const routeName = '/';
|
||||
|
||||
@override
|
||||
_CalculatorPageState createState() => _CalculatorPageState();
|
||||
}
|
||||
|
||||
class _CalculatorPageState extends State<CalculatorPage> {
|
||||
int _counter = 0;
|
||||
double _weight = 60;
|
||||
double _height = 165;
|
||||
double _age = 18;
|
||||
int _gender = 0; // male = 1; female = 0
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
});
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
int bodyMassIndex() => ((_weight / (_height * _height)) * 10000).round();
|
||||
|
||||
int bodyFatPercentage() =>
|
||||
(1.2 * bodyMassIndex() + .23 * _age - 10.8 * _gender - 5.4).round();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Scaffold(
|
||||
appBar: AppBar(
|
||||
|
|
@ -24,22 +34,89 @@ class _CalculatorPageState extends State<CalculatorPage> {
|
|||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'You have pushed the button this many times:',
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Ink(
|
||||
decoration: const ShapeDecoration(
|
||||
color: Colors.lightGreen,
|
||||
shape: CircleBorder(),
|
||||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.female),
|
||||
tooltip: 'Choose female gender',
|
||||
onPressed: () {
|
||||
setState(() => _gender = 0);
|
||||
},
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Ink(
|
||||
decoration: const ShapeDecoration(
|
||||
color: Colors.lightGreen,
|
||||
shape: CircleBorder(),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.male),
|
||||
tooltip: 'Choose male gender',
|
||||
onPressed: () {
|
||||
setState(() => _gender = 1);
|
||||
},
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text('Weight'),
|
||||
Text("${_weight.round().toString()} kg"),
|
||||
Slider(
|
||||
value: _weight,
|
||||
min: 0,
|
||||
max: 100,
|
||||
divisions: 100,
|
||||
label: _weight.round().toString(),
|
||||
onChanged: (double value) => setState(() => _weight = value),
|
||||
),
|
||||
Text('Height'),
|
||||
Text("${_height.round().toString()} cm"),
|
||||
Slider(
|
||||
value: _height,
|
||||
min: 100,
|
||||
max: 200,
|
||||
divisions: 100,
|
||||
label: _height.round().toString(),
|
||||
onChanged: (double value) => setState(() => _height = value),
|
||||
),
|
||||
Text('Age'),
|
||||
Text("${_age.round().toString()} years old"),
|
||||
Slider(
|
||||
value: _age,
|
||||
min: 10,
|
||||
max: 100,
|
||||
divisions: 100,
|
||||
label: _age.round().toString(),
|
||||
onChanged: (double value) => setState(() => _age = value),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
print(
|
||||
"BMI: ${bodyMassIndex()}; BFP: ${bodyFatPercentage()}");
|
||||
Navigator.pushNamed(
|
||||
context,
|
||||
ResultPage.routeName,
|
||||
arguments: Results(bodyMassIndex(), bodyFatPercentage()),
|
||||
);
|
||||
},
|
||||
child: Text('Calculate'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
tooltip: 'Increment',
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'calculator.dart';
|
||||
import 'result.dart';
|
||||
|
||||
void main() => runApp(BMIApp());
|
||||
|
||||
|
|
@ -8,11 +9,11 @@ class BMIApp extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) => MaterialApp(
|
||||
title: 'BMI/BFP Calculator',
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.green,
|
||||
),
|
||||
home: CalculatorPage(),
|
||||
theme: ThemeData(primarySwatch: Colors.green),
|
||||
initialRoute: '/',
|
||||
routes: {
|
||||
CalculatorPage.routeName: (context) => CalculatorPage(),
|
||||
ResultPage.routeName: (context) => ResultPage(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
37
lib/result.dart
Normal file
37
lib/result.dart
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class Results {
|
||||
int bodyMassIndex;
|
||||
int bodyFatPercentage;
|
||||
|
||||
Results(this.bodyMassIndex, this.bodyFatPercentage);
|
||||
}
|
||||
|
||||
class ResultPage extends StatelessWidget {
|
||||
static const routeName = '/results';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final results = ModalRoute.of(context)!.settings.arguments as Results;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Your results"),
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
"Your results: BMI: ${results.bodyMassIndex}; BFP: ${results.bodyFatPercentage}"),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Text('Go back!'),
|
||||
),
|
||||
],
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue