mirror of
https://github.com/rjNemo/bmi_calculator_app
synced 2026-06-12 13:26:46 +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 over 40 : red - morbid obesity
|
||||||
- [ ] bmi tracker: date, value, graph
|
- [ ] bmi tracker: date, value, graph
|
||||||
- [ ] profile: save age, height, genre, local storage
|
- [ ] profile: save age, height, genre, local storage
|
||||||
- [ ] bmi on second screen
|
- [x] bmi on second screen
|
||||||
- [ ] feedback on genre select
|
- [ ] feedback on genre select
|
||||||
|
|
||||||
* [doc](https://www.santepratique.fr/nutrition/calcul-imc)
|
* [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 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'result.dart';
|
||||||
|
|
||||||
class CalculatorPage extends StatefulWidget {
|
class CalculatorPage extends StatefulWidget {
|
||||||
CalculatorPage({Key? key}) : super(key: key);
|
CalculatorPage({Key? key}) : super(key: key);
|
||||||
final String title = 'BMI Calculator';
|
final String title = 'BMI Calculator';
|
||||||
|
static const routeName = '/';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
_CalculatorPageState createState() => _CalculatorPageState();
|
_CalculatorPageState createState() => _CalculatorPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CalculatorPageState extends State<CalculatorPage> {
|
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() {
|
@override
|
||||||
setState(() {
|
void initState() {
|
||||||
_counter++;
|
super.initState();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bodyMassIndex() => ((_weight / (_height * _height)) * 10000).round();
|
||||||
|
|
||||||
|
int bodyFatPercentage() =>
|
||||||
|
(1.2 * bodyMassIndex() + .23 * _age - 10.8 * _gender - 5.4).round();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => Scaffold(
|
Widget build(BuildContext context) => Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
|
|
@ -24,22 +34,89 @@ class _CalculatorPageState extends State<CalculatorPage> {
|
||||||
),
|
),
|
||||||
body: Center(
|
body: Center(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Row(
|
||||||
'You have pushed the button this many times:',
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
children: <Widget>[
|
||||||
|
Expanded(
|
||||||
|
child: Ink(
|
||||||
|
decoration: const ShapeDecoration(
|
||||||
|
color: Colors.lightGreen,
|
||||||
|
shape: CircleBorder(),
|
||||||
|
),
|
||||||
|
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(
|
Text('Weight'),
|
||||||
'$_counter',
|
Text("${_weight.round().toString()} kg"),
|
||||||
style: Theme.of(context).textTheme.headline4,
|
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,18 +1,19 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'calculator.dart';
|
import 'calculator.dart';
|
||||||
|
import 'result.dart';
|
||||||
|
|
||||||
void main() => runApp(BMIApp());
|
void main() => runApp(BMIApp());
|
||||||
|
|
||||||
class BMIApp extends StatelessWidget {
|
class BMIApp extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => MaterialApp(
|
Widget build(BuildContext context) => MaterialApp(
|
||||||
title: 'BMI/BFP Calculator',
|
title: 'BMI/BFP Calculator',
|
||||||
theme: ThemeData(
|
theme: ThemeData(primarySwatch: Colors.green),
|
||||||
primarySwatch: Colors.green,
|
initialRoute: '/',
|
||||||
),
|
routes: {
|
||||||
home: CalculatorPage(),
|
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