Skip to main content

BMI CALCULATOR USING FLUTTER || FLUTTER IMPLEMENTATION

 

A Body Mass Index (BMI) calculator is an application that helps determine an individual's body weight status based on their height and weight. Here is an example implementation of a BMI calculator using Flutter:

 

import 'package:flutter/material.dart';

 

void main() {

  runApp(const MyApp());

}

 

class MyApp extends StatelessWidget{

  const MyApp({Key? key}) : super(key: key);

 

  @override

  Widget build(BuildContext context){

    return MaterialApp(

      title: 'Flutter Demo',

      debugShowCheckedModeBanner: false,

      theme: ThemeData(

        primarySwatch: Colors.cyan,

      ),

      home: const MyHomePage(),

    );

  }

}

 

class MyHomePage extends StatefulWidget {

  const MyHomePage({Key? key}) : super(key: key);

 

  @override

  State<MyHomePage> createState() => _MyHomePageState();

}

 

class _MyHomePageState extends State<MyHomePage> {

 

  var wtController = TextEditingController();

  var ftController = TextEditingController();

  var inController = TextEditingController();

  var result = "";

 

  @override

  Widget build(BuildContext context) {

 

    return Scaffold(

      appBar: AppBar(

 

        title: Text('BMI Calculator'),

      ),

      body: Center(

        child: Container(

          width: 300,

          child: Column(

            mainAxisAlignment: MainAxisAlignment.center,

            children: [

              Text('BMI', style:TextStyle(

                fontSize: 34, fontWeight: FontWeight.w700

              ),),

 

              SizedBox(height: 21,),

 

              TextField(

                controller: wtController,

                decoration: InputDecoration(

                  label: Text('Weight (in kg)'),

                  prefixIcon: Icon(Icons.line_weight),

                ),

                keyboardType: TextInputType.number,

              ),

 

              SizedBox(height: 11,),

 

              TextField(

                controller: ftController,

                decoration: InputDecoration(

                  label: Text('Height in feet'),

                  prefixIcon: Icon(Icons.height),

                ),

                keyboardType: TextInputType.number,

              ),

 

              SizedBox(height: 11,),

 

              TextField(

                controller: inController,

                decoration: InputDecoration(

                  label: Text('Height in inches'),

                  prefixIcon: Icon(Icons.height),

                ),

                keyboardType: TextInputType.number,

              ),

 

              SizedBox(height: 21,),

 

              ElevatedButton(onPressed: (){

 

                var wt = wtController.text.toString();

                var ft = ftController.text.toString();

                var inch = inController.text.toString();

 

                if(wt !="" && ft!="" && inch !=""){

 

                  var iwt = int.parse(wt);

                  var ift = int.parse(ft);

                  var iinch = int.parse(inch);

 

                  var tinch = (ift * 12) + iinch;

                  var tcm = tinch * 2.54;

                  var tm = tcm / 100;

 

                  var bmi = iwt/(tm * tm);

 

                  var msg = "";

 

                  if(bmi>25){

                    msg = "You are Over Weight :(";

                  }else if(bmi<18){

                    msg = "You are Underweight :(";

                  }else{

                    msg = "You are Healthy :)";

                  }

 

                  setState(() {

                    result = "$msg \n Your BMI is: ${bmi.toStringAsFixed(2)} ";

                  });

                }else{

                  setState((){

                    result = "All Fields Required!!";

                  });

 

                }

              },

 

 

                  child:Text('Calculate')),

 

              SizedBox(height:11,),

 

              Text(result, style: TextStyle(fontSize: 19),),

 

            ],

          ),

        ),

      )

    );

  }

}

 

 




Comments

Popular posts from this blog

Can Chat GPT Predict About Stock Market

Can ChatGPT predict the stock market? To answer this question, it's crucial to understand how ChatGPT operates. Developed by OpenAI, ChatGPT is an advanced artificial intelligence language model capable of comprehending and responding to natural language input. It engages in human-like conversations with users, having been trained on extensive text data using a deep neural network. Primarily used for applications like chatbots, virtual assistants, and customer service interactions, ChatGPT's versatility allows it to understand and respond to a wide array of topics. The model employs a deep learning architecture known as a transformer model, trained on a substantial corpus of text data. This training enables the model to grasp natural language intricacies and the connections between words and phrases. When a user inputs text, ChatGPT processes it through the transformer model, generating a response based on its understanding of the input text. Techniques such as attention mechan...

Web Based Technologies and Multimedia Applications || NPTEL WEEK 1 ASSIGNMENT SOLUTIONS

1.) The following are different ways of sharing information through Internet   Posting to Social Network   Uploading to cloud storage such as Google Drive   Sending through a mailing list   All of the above Answer: All of the above  2.) The following is a website where entries are written as commentary or news on a particular subject such as food, politics, or local news   Blog   Twitter   Instagram   None of the above Answer: Blog 3.) FTP stands for   Food Transfer Programme   File Transfer Protocol   File Transfer Programming   Facebook To Python Answer: File Transfer Protocol 4.) The following enables access to computing resources remotely   FTP   VPN   Blog   Twitter Answer: VPN 5.) The following allows an Internet host Computer to become a terminal of another host on the Internet   TELNET   Google Groups   Microsoft OneDrive   None of the above Answer: TELNET 6.) To which protoc...

An Introduction To Programming Through C++ || NPTEL Week-3 Programming Assignment 3.1

  You are currently at the origin (0, 0) and will be given commands to either go Right (R), Left (L), Up (U) or Down (D) by a certain number of steps. At the end of all these commands, you will be signaled to stop by reading the character ‘E’, after which you need to output your position in the x-y plane. The four kinds of movements are the following (direction followed by number of steps in that direction): R number_of_steps : You need to increase your x-coordinate by “number_of_steps”. L number_of_steps : You need to decrease your x-coordinate by “number_of_steps”. U number_of_steps : You need to increase your y-coordinate by “number_of_steps”. D number_of_steps : You need to decrease your y-coordinate by “number_of_steps”. INPUT: Direction number_of_steps (a character and integer separated by a space) . . .  E (command to stop) OUTPUT: x y SOLUTION: int main() { char U, D, R, L, E; int x = 0, y = 0; int steps; char direction; while (1) { c...