Skip to content

Commit 43b6c00

Browse files
committed
Fin Projet
1 parent 16b7089 commit 43b6c00

8 files changed

+162
-110
lines changed

lib/calculatorBrain.dart

-16
This file was deleted.

lib/calculator_brain.dart

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'dart:math';
2+
3+
class CalculatorBrain {
4+
5+
final int taille;
6+
final int poids;
7+
8+
CalculatorBrain({required this.taille, required this.poids});
9+
10+
double _bmi=0;
11+
12+
String calculateBMI() {
13+
_bmi = poids / pow(taille / 100, 2);
14+
return _bmi.toStringAsFixed(1);
15+
}
16+
17+
String getResult() {
18+
if (_bmi >= 25) {
19+
return 'Surpoids';
20+
} else if (_bmi > 18.5) {
21+
return 'Normal';
22+
} else {
23+
return 'Insuffisance pondérale';
24+
}
25+
}
26+
27+
String getInterpretation() {
28+
if (_bmi >= 25) {
29+
return 'Vous êtes en sûrpoids. Faites du sport.';
30+
} else if (_bmi >= 18.5) {
31+
return 'Vous avez un corps normal. Félicitations !';
32+
} else {
33+
return 'Vous etes en dessous du poid normal. Vous devriez songer a manger unpeu plus.';
34+
}
35+
}
36+
}

lib/components/reusable_card.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import 'package:flutter/material.dart';
2+
23
class ReusableCard extends StatelessWidget {
3-
ReusableCard({required this.largeur, required this.couleur,
4-
required this.containerChild});
4+
ReusableCard(
5+
{super.key,
6+
required this.largeur,
7+
required this.couleur,
8+
required this.containerChild});
59
final largeur;
610
final couleur;
711
Widget containerChild;
@@ -10,13 +14,12 @@ class ReusableCard extends StatelessWidget {
1014
Widget build(BuildContext context) {
1115
return Expanded(
1216
child: Container(
13-
child: containerChild,
1417
margin: const EdgeInsets.all(10.0),
1518
height: 200.0,
1619
width: largeur,
1720
decoration: BoxDecoration(
18-
color: couleur,
19-
borderRadius: BorderRadius.circular(10.0))),
21+
color: couleur, borderRadius: BorderRadius.circular(10.0)),
22+
child: containerChild),
2023
);
2124
}
22-
}
25+
}

lib/components/rounded_button.dart

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import 'package:flutter/material.dart';
2+
23
class RoundedButton extends StatelessWidget {
3-
RoundedButton({required this.icon,required this.onPress});
4+
const RoundedButton({super.key, required this.icon, required this.onPress});
45
final IconData icon;
5-
final Function onPress;
6+
final Function onPress;
67
@override
78
Widget build(BuildContext context) {
89
return RawMaterialButton(
9-
child:Icon(icon),
10-
onPressed: (){
10+
onPressed: () {
1111
onPress();
1212
},
1313
elevation: 6.0,
14-
constraints: BoxConstraints.tightFor(width: 40.0,height: 40.0),
14+
constraints: const BoxConstraints.tightFor(width: 40.0, height: 40.0),
1515
shape: RoundedRectangleBorder(
16-
borderRadius: BorderRadius.circular(10.0,),),
17-
fillColor: Color(0XFF4C4F5E),
16+
borderRadius: BorderRadius.circular(
17+
10.0,
18+
),
19+
),
20+
fillColor: const Color(0XFF4C4F5E),
21+
child: Icon(icon),
1822
);
1923
}
20-
}
24+
}

lib/main.dart

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
import 'package:bmi/screens/resultPage.dart';
2-
import 'package:flutter/material.dart';
31
import 'package:bmi/screens/input_page.dart';
2+
import 'package:flutter/material.dart';
43

54
void main() {
6-
runApp( MyApp());
5+
runApp( const MyApp());
76
}
87

98
class MyApp extends StatelessWidget {
9+
const MyApp({super.key});
10+
1011
@override
1112
Widget build(BuildContext context) {
1213
return MaterialApp(
14+
debugShowCheckedModeBanner: false,
1315
theme: ThemeData.dark().copyWith(
14-
primaryColor: const Color(0xFF0A0E21),
16+
primaryColor: Colors.black12,
1517
scaffoldBackgroundColor: const Color(0xFF0A0E21)),
16-
// home: InputPage(),
17-
18-
initialRoute: '/',
19-
routes:{
20-
'/' : (context)=> InputPage(),
21-
'/resultat' : (context)=> ResultPage(),
22-
}
18+
home: const InputPage(),
2319
);
24-
2520
}
2621
}

lib/screens/input_page.dart

+30-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import 'package:bmi/screens/resultPage.dart';
1+
import 'package:bmi/calculator_brain.dart';
2+
import 'package:bmi/screens/result_page.dart';
23
import 'package:flutter/material.dart';
34
import '../components/reusable_card.dart';
45
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
@@ -21,7 +22,7 @@ class _InputPageState extends State<InputPage> {
2122
Widget build(BuildContext context) {
2223
return Scaffold(
2324
appBar: AppBar(
24-
title: Text('BMI CALCULATOR'),
25+
title: const Text('BMI CALCULATOR'),
2526
),
2627
body: Column(
2728
children: [
@@ -57,17 +58,17 @@ class _InputPageState extends State<InputPage> {
5758
mainAxisAlignment: MainAxisAlignment.center,
5859
children: [
5960
Text(ma_taille.toString(), style: kMyTextStyle),
60-
Text('cm'),
61+
const Text('cm'),
6162
],
6263
),
6364
),
6465
),
6566
SliderTheme(
6667
data: SliderTheme.of(context).copyWith(
67-
thumbColor: Color(0xFFEB1555),
68+
thumbColor: const Color(0xFFEB1555),
6869
activeTrackColor: Colors.white,
69-
inactiveTrackColor: Color(0xFF8D8E98),
70-
overlayColor: Color(0x29EB1555),
70+
inactiveTrackColor: const Color(0xFF8D8E98),
71+
overlayColor: const Color(0x29EB1555),
7172
thumbShape:
7273
const RoundSliderThumbShape(enabledThumbRadius: 15.0),
7374
overlayShape:
@@ -94,7 +95,7 @@ class _InputPageState extends State<InputPage> {
9495
couleur: Colors.teal,
9596
containerChild: Column(
9697
children: [
97-
Text(
98+
const Text(
9899
'Poids',
99100
style: kMyTextStyle,
100101
),
@@ -106,7 +107,7 @@ class _InputPageState extends State<InputPage> {
106107
mon_poids.toString(),
107108
style: kMyTextStyle,
108109
),
109-
Text('KG')
110+
const Text('KG')
110111
],
111112
),
112113
Row(
@@ -138,7 +139,7 @@ class _InputPageState extends State<InputPage> {
138139
couleur: Colors.teal,
139140
containerChild: Column(
140141
children: [
141-
Text(
142+
const Text(
142143
'Age',
143144
style: kMyTextStyle,
144145
),
@@ -150,7 +151,7 @@ class _InputPageState extends State<InputPage> {
150151
mon_age.toString(),
151152
style: kMyTextStyle,
152153
),
153-
Text('ans')
154+
const Text('ans')
154155
],
155156
),
156157
Row(
@@ -180,26 +181,29 @@ class _InputPageState extends State<InputPage> {
180181
],
181182
),
182183
Container(
183-
margin: EdgeInsets.symmetric(horizontal: 10.0),
184-
child: Center(
185-
child: TextButton(
186-
onPressed: () {
187-
188-
Navigator.push(
189-
context,
190-
MaterialPageRoute(builder: (context) => const ResultPage()),
191-
);
192-
},
193-
child: const Text('CALCUL BMI!',
194-
style: TextStyle(fontSize: 40.0, fontWeight: FontWeight.bold),),
195-
),
196-
),
184+
margin: const EdgeInsets.symmetric(horizontal: 10.0),
197185
height: 80.0,
198186
width: double.infinity,
199-
color: Color(0xFFEB1555),
187+
color: const Color(0xFFEB1555),
188+
child: TextButton(
189+
onPressed: () {
190+
CalculatorBrain cal = CalculatorBrain(taille: ma_taille, poids: mon_poids);
191+
Navigator.push(context, MaterialPageRoute(builder: (context)=>ResultPage(
192+
mon_bmi: cal.calculateBMI(),
193+
mon_resultat: cal.getResult(),
194+
interpretation: cal.getInterpretation()
195+
)));
196+
},
197+
child: const Center(
198+
child: Text(
199+
'CALCULER BMI',
200+
style: TextStyle(fontSize: 40.0, fontWeight: FontWeight.bold),
201+
),
202+
),
203+
),
200204
),
201205
],
202206
),
203207
);
204208
}
205-
}
209+
}

lib/screens/resultPage.dart

-42
This file was deleted.

lib/screens/result_page.dart

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import 'package:flutter/material.dart';
2+
3+
class ResultPage extends StatelessWidget {
4+
5+
final String mon_bmi;
6+
final String mon_resultat;
7+
final String interpretation;
8+
9+
const ResultPage({super.key, required this.mon_bmi, required this.mon_resultat, required this.interpretation});
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
return Scaffold(
14+
appBar: AppBar(
15+
title: const Text("BMI Calculator"),
16+
),
17+
body:
18+
Center(
19+
child: Column(
20+
children: [
21+
Expanded(
22+
child: Container(
23+
decoration: BoxDecoration(
24+
color: Colors.lightBlue
25+
),
26+
child: Text(textAlign: TextAlign.center,"Votre indice corporelle: "+
27+
mon_bmi,
28+
style: const TextStyle(
29+
fontSize: 40.0,
30+
),
31+
),
32+
33+
),
34+
35+
),
36+
Expanded(
37+
child: Container(
38+
child: Text(
39+
mon_resultat,
40+
style: const TextStyle(
41+
fontSize: 40.0,
42+
),
43+
),
44+
45+
),
46+
47+
),
48+
Expanded(
49+
child: Container(
50+
decoration: BoxDecoration(color: Colors.green),
51+
child: Text(
52+
textAlign:TextAlign.center,
53+
interpretation,
54+
style: const TextStyle(
55+
fontSize: 30.0,
56+
color : Colors.greenAccent,
57+
),
58+
),
59+
),
60+
61+
),
62+
],
63+
),
64+
),
65+
);
66+
67+
}
68+
}

0 commit comments

Comments
 (0)