3/23/2023 0 Comments Bmi calculator app![]() data type class: SP2023_Adult_yourLastName.You must provide two classes in this project: In this Lab3 part1, we are going to rewrite this Lab2 part2 (that’s one in the above) by using Object Oriented Programming. Notes: You must complete reading input before displaying the output and write the comments for each task (not for each line of the code)įile: SP2023_AdultBMI_Calculator_Martinez.java The BMI rate is displayed in 9 output lines in the following format with the name and numbers should be aligned to the right and with 2 decimal digits. The application should display message to ask and read from the keyboard users to enter the users’ information from the keyboard about: _result = null ? "Enter Value" : " $_result.toStringAsFixed( 2)",ĭouble weight = double.parse(_weightController.C++ application to help users to calculate the BMI rate of Adults.īMI (Body Mass Index) is a measure of body fat based on height and weight of adult men or women. MainAxisAlignment: MainAxisAlignment.center, Padding: EdgeInsets.symmetric(horizontal: 10.0), import 'package:flutter/material.dart' Ĭlass MyApp extends StatelessWidget build(BuildContext context)Ĭlass Demo extends StatefulWidget createState() => _DemoState() Ĭlass _DemoState extends State final TextEditingController _heightController = TextEditingController() The full source code be also found at the github but code is not very big so I put it here also. You can share the feedback in the comment or tweet about the also (don’t forget to tag Full Source Code If you are beginner and understand everything then it’s really good because you learn lots of important things. ![]() Let me know if I succeed in doing that or not or you still face issue in understanding this. I break down the everything into small parts so that it will become easy to follow. toStringAsFixed allow us to limit the number of number after decimal._result = null ? "Enter Value" : "BMI : $_result.toStringAsFixed( 2)", Let’s make the UI consistent by doing a simple tweaks. There could be 2 digit after decimal or 8 digit after decimal. There is one more issue that the decimal value could be very long i.e. The above code is good and everything works fine but there is a UI related issue which user will face someday. In this step we will limit the two digit after the decimal so that it will look consistent and not break the UI. _result = null ? "Enter Value" : "BMI : $_result", We just defined the result variable so If would have called this earlier then this would be injustice for the reader. We are still missing one things, we have never called the result variable in the UI. The app is showing the result in the console and we want in the app. In the previous step we created the BMI calculator which kind of works but there is problem. Let’s attach the method to the button click or press. The above code is for refernce so that you can know the formula for BMI(in case you don’t know).ĭouble height = double.parse(_heightController.text) / 100 ĭouble weight = double.parse(_weightController.text) double calculateBMI( double height, double weight) Let me show you the formula first then we will add this to our file demo.dart based on our case. So whenever we will click on the button it will calculate the BMI. Now we will write the function to Calculator BMI and add the event with button click event. Let attach to the the respective text field, So that we could have control over the Text Field. Now we have defined two controller for two Text Field. final TextEditingController _heightController = TextEditingController() įinal TextEditingController _weightController = TextEditingController() It will help us in getting the value from the field. Now we will bind the input controller with the weight and height field. The above Code UI WILL BE ADDED HERE Step 3 Let’s convert the skeleton to the flutter app. Let’s build the basic scaffold firs then we will move into depth. These are the widget which I will be using in the application. Let’s start the app by building the UI and it’s easy but I will break into small part so that it will be more clear. Here is the video tutorial of building the BMI calculator, If you prefer watching video then you should watch this. This was orignally published at nstack.in Get Started
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |