Creating a BMI app in flutter
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:intl/intl.dart';
import 'package:waris/IntroPage.dart';
import 'package:waris/ProfileScreen.dart';
//import 'package:waris/splash_screen.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
textTheme: TextTheme(
headline1: TextStyle(
fontWeight: FontWeight.bold, fontSize: 25, color: Colors.black),
subtitle1: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.green)),
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget{
@override
State<StatefulWidget> createState() {
return MyHomeState();
}
}
class MyHomeState extends State<MyHomePage>{
var wtController =TextEditingController();
var fttController =TextEditingController();
var inchController =TextEditingController();
var result = "";
var bgColor=Colors.yellow;
var count = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Stateful widget'),
),
body:Center(
child: Container(
color: bgColor,
width: 400,
child: Column(
mainAxisAlignment: MainAxisAlignment.center ,
children: [
Text('BMI Calculator',style: TextStyle(fontSize: 34,fontWeight: FontWeight.bold),),
TextField(
controller: wtController,
decoration: InputDecoration(
label: Text('Enter your weight (in Kgs) '),
prefixIcon: Icon(Icons.line_weight)
),
keyboardType: TextInputType.number,
),
TextField(
controller: fttController,
decoration: InputDecoration(
label: Text('Enter you Height (in Feet) '),
prefixIcon: Icon(Icons.height)
),
keyboardType: TextInputType.number,
),
TextField(
controller: inchController,
decoration: InputDecoration(
label: Text('Enter your Height (in Inches) '),
prefixIcon: Icon(Icons.height)
),
keyboardType: TextInputType.number,
),
ElevatedButton(onPressed: (){
var wt = wtController.text.toString();
var ftt = fttController.text.toString();
var inch = inchController.text.toString();
if(wt != "" && ftt !="" && inch !=""){
var iwt = int.parse(wt);
var iftt = int.parse(ftt);
var iinch = int.parse(inch);
var tinch = (iftt*12) + iinch;
var tCm = tinch*2.54;
var tM = tCm/100;
var bmi = iwt/(tM*tM);
var message= "";
if(bmi>25){
message="You are overweight";
bgColor = Colors.orange;
} else if(bmi<18){
message = 'You are underWeight';
bgColor= Colors.red;
}else{
message= 'You are healthy';
bgColor = Colors.green;
}
setState(() {
result = "$message \nYour BMI is :${bmi.toStringAsFixed(4)}";
});
}else{
setState(() {
result = "plz fill all required fields!!";
});
}
}, child: Text('Calculate')),
Text(result,style: TextStyle(
fontSize: 16
),)
],
),
),
)
);
}
}
Comments
Post a Comment