Advertisement
Guest User

Flutt

a guest
Jun 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.13 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() => runApp(new MyApp());
  4.  
  5. class MyApp extends StatefulWidget {
  6.   @override
  7.   _MyAppState createState() => new _MyAppState();
  8. }
  9.  
  10. class _MyAppState extends State<MyApp> {
  11.   final TextEditingController _ageController = new TextEditingController();
  12.   final TextEditingController _heightController = new TextEditingController();
  13.   final TextEditingController _weightController = new TextEditingController();
  14.  
  15.  
  16.   double bmi = 0.0;
  17.  
  18.   _calculateClicked() {
  19.     setState(() {
  20.           int age = int.parse(_ageController.text);
  21.           double height = double.parse(_heightController.text);
  22.           int weight = int.parse(_weightController.text);
  23.          
  24.  
  25.           void calculatebmi(){
  26.             double inches = height*12;
  27.             bmi = weight/2;
  28.           }
  29.           calculatebmi();
  30.         });
  31.   }
  32.  
  33.   @override
  34.   Widget build(BuildContext context) {
  35.     return new MaterialApp(
  36.       debugShowCheckedModeBanner: false,
  37.       title: "Bmi challenge app",
  38.       home: new Scaffold(
  39.         appBar: new AppBar(
  40.           title: Text('BMI'),
  41.           centerTitle: true,
  42.           backgroundColor: Colors.pink,
  43.         ),
  44.         body: new Column(
  45.           children: <Widget>[
  46.             new Center(
  47.               child: new Image(
  48.                 image: new NetworkImage(
  49.                   "http://www.simpleimageresizer.com/_uploads/photos/761d18ce/bmi-logo-880x655_1_20.png",
  50.                 ),
  51.               ),
  52.             ),
  53.             new Card(
  54.                 color: Colors.grey[300],
  55.                 child: new Column(
  56.                   mainAxisAlignment: MainAxisAlignment.center,
  57.                   children: <Widget>[
  58.                     new Padding(
  59.                       padding: EdgeInsets.only(bottom: 25.0, top: 15.0),
  60.                       child: new TextField(
  61.                         controller: _ageController,
  62.                         decoration: new InputDecoration(
  63.                             icon: new Icon(
  64.                               Icons.person_outline,
  65.                             ),
  66.                             hintText: "Age",
  67.                             hintStyle: new TextStyle(fontSize: 17.0)),
  68.                       ),
  69.                     ),
  70.                     new Padding(
  71.                       padding: EdgeInsets.only(bottom: 25.0),
  72.                       child: new TextField(
  73.                         controller: _heightController,
  74.                         decoration: new InputDecoration(
  75.                             icon: new Icon(
  76.                               Icons.insert_chart,
  77.                             ),
  78.                             hintText: "Height in feet",
  79.                             hintStyle: new TextStyle(fontSize: 17.0)),
  80.                       ),
  81.                     ),
  82.                     new Padding(
  83.                       padding: EdgeInsets.only(bottom: 25.0),
  84.                       child: new TextField(
  85.                         controller: _weightController,
  86.                         decoration: new InputDecoration(
  87.                             icon: new Icon(
  88.                               Icons.line_weight,
  89.                             ),
  90.                             hintText: "Weight in lb",
  91.                             hintStyle: new TextStyle(fontSize: 17.0)),
  92.                       ),
  93.                     ),
  94.                     new Padding(
  95.                         padding: new EdgeInsets.only(bottom: 15.0),
  96.                         child: new MaterialButton(
  97.                           onPressed: _calculateClicked(),
  98.                           color: Colors.pink,
  99.                           child: new Text(
  100.                             "Calculate",
  101.                             style: new TextStyle(color: Colors.white),
  102.                           ),
  103.                           minWidth: 100.0,
  104.                           height: 45.0,
  105.                         )),
  106.                   ],
  107.                 )),
  108.             new Padding(
  109.               padding: EdgeInsets.only(top: 15.0),
  110.               child: new Text("Your BMI: $bmi"),
  111.             )
  112.           ],
  113.         ),
  114.       ),
  115.     );
  116.   }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement