feat: layout

This commit is contained in:
Ruidy 2021-07-04 12:22:00 +02:00
parent 1bb30cce2a
commit 5a7ac79d22
2 changed files with 106 additions and 31 deletions

View file

@ -2,13 +2,13 @@
Compute and track your Body Mass Index and Body Fat Percentage
## TODO
## Features
- [ ] bmi between 18.5 and 25 : green - normal
- [ ] bmi below 18.5 : pink - too skinny
- [ ] bmi between 25 and 30 : yellow - overweight
- [ ] bmi between 30 and 40 : orange - obesity
- [ ] bmi over 40 : red - morbid obesity
- [x] bmi between 18.5 and 25 : green - normal
- [x] bmi below 18.5 : pink - too skinny
- [x] bmi between 25 and 30 : yellow - overweight
- [x] bmi between 30 and 40 : orange - obesity
- [x] bmi over 40 : red - morbid obesity
- [ ] bmi tracker: date, value, graph
- [ ] profile: save age, height, genre, local storage
- [x] bmi on second screen

View file

@ -4,16 +4,47 @@ class Results {
int bodyMassIndex;
int bodyFatPercentage;
Results(this.bodyMassIndex, this.bodyFatPercentage);
late Map results;
String category() {
if (bodyMassIndex > 12) {
return "Normal";
}
return "Too much";
Results(this.bodyMassIndex, this.bodyFatPercentage) {
results = _results();
}
Icon icon() => Icon(Icons.female);
Map _results() {
if (bodyMassIndex > 40) {
return {
"category": "Morbid obesity",
"icon": "🤒",
"color": Colors.red,
};
}
if (bodyMassIndex > 30) {
return {
"category": "Obesity",
"icon": "🤕",
"color": Colors.orange,
};
}
if (bodyMassIndex > 25) {
return {
"category": "Overweight",
"icon": "🛑",
"color": Colors.yellow,
};
}
if (bodyMassIndex > 18) {
return {
"category": "Normal",
"icon": "",
"color": Colors.green,
};
}
return {
"category": "Too skinny",
"icon": "🤔",
"color": Colors.pink,
};
}
}
class ResultPage extends StatelessWidget {
@ -21,32 +52,76 @@ class ResultPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final results = ModalRoute.of(context)!.settings.arguments as Results;
final args = ModalRoute.of(context)!.settings.arguments as Results;
return Scaffold(
appBar: AppBar(
title: Text("Your results"),
),
body: Center(
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
results.icon(), //
Text("Below are your results given your height, age and gender."),
Text(
"Your BMI is ${results.bodyMassIndex}, and your BFP is ${results.bodyFatPercentage}, indicating your weight is in the ${results.category()} for adults of your height.",
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
"Your current BMI: ${args.bodyMassIndex}",
style: TextStyle(fontSize: 28.0),
),
Text(
"Your current BFP: ${args.bodyFatPercentage}%",
style: TextStyle(fontSize: 28.0),
),
Text(
args.results["icon"],
style: TextStyle(fontSize: 40.0),
),
RichText(
text: TextSpan(
style: TextStyle(
fontSize: 16.0,
color: Colors.black,
),
children: <TextSpan>[
TextSpan(text: 'Your BMI is '),
TextSpan(
text: '${args.bodyMassIndex}',
style: TextStyle(
fontWeight: FontWeight.bold,
color: args.results["color"],
),
),
TextSpan(text: ', and your BFP is '),
TextSpan(
text: '${args.bodyFatPercentage}%',
style: TextStyle(
fontWeight: FontWeight.bold,
color: args.results["color"],
),
),
TextSpan(text: ', indicating your weight is in the '),
TextSpan(
text: '${args.results["category"]}',
style: TextStyle(
fontWeight: FontWeight.bold,
color: args.results["color"],
),
),
TextSpan(text: ' range for adults of your height.'),
],
),
),
Text(
"Maintaining a healthy weight may reduce the risk of chronic diseases associated with overweight and obesity.",
),
ElevatedButton(
onPressed: () => Navigator.pop(context),
child: Text('Recalculate BMI'),
),
],
),
Text(
"Maintaining a healthy weight may reduce the risk of chronic diseases associated with overweight and obesity.",
),
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Recalculate BMI'),
),
],
)),
),
),
);
}
}