Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() => runApp(new MyApp());
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => new _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- final TextEditingController _ageController = new TextEditingController();
- final TextEditingController _heightController = new TextEditingController();
- final TextEditingController _weightController = new TextEditingController();
- double bmi = 0.0;
- _calculateClicked() {
- setState(() {
- int age = int.parse(_ageController.text);
- double height = double.parse(_heightController.text);
- int weight = int.parse(_weightController.text);
- void calculatebmi(){
- double inches = height*12;
- bmi = weight/2;
- }
- calculatebmi();
- });
- }
- @override
- Widget build(BuildContext context) {
- return new MaterialApp(
- debugShowCheckedModeBanner: false,
- title: "Bmi challenge app",
- home: new Scaffold(
- appBar: new AppBar(
- title: Text('BMI'),
- centerTitle: true,
- backgroundColor: Colors.pink,
- ),
- body: new Column(
- children: <Widget>[
- new Center(
- child: new Image(
- image: new NetworkImage(
- "http://www.simpleimageresizer.com/_uploads/photos/761d18ce/bmi-logo-880x655_1_20.png",
- ),
- ),
- ),
- new Card(
- color: Colors.grey[300],
- child: new Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- new Padding(
- padding: EdgeInsets.only(bottom: 25.0, top: 15.0),
- child: new TextField(
- controller: _ageController,
- decoration: new InputDecoration(
- icon: new Icon(
- Icons.person_outline,
- ),
- hintText: "Age",
- hintStyle: new TextStyle(fontSize: 17.0)),
- ),
- ),
- new Padding(
- padding: EdgeInsets.only(bottom: 25.0),
- child: new TextField(
- controller: _heightController,
- decoration: new InputDecoration(
- icon: new Icon(
- Icons.insert_chart,
- ),
- hintText: "Height in feet",
- hintStyle: new TextStyle(fontSize: 17.0)),
- ),
- ),
- new Padding(
- padding: EdgeInsets.only(bottom: 25.0),
- child: new TextField(
- controller: _weightController,
- decoration: new InputDecoration(
- icon: new Icon(
- Icons.line_weight,
- ),
- hintText: "Weight in lb",
- hintStyle: new TextStyle(fontSize: 17.0)),
- ),
- ),
- new Padding(
- padding: new EdgeInsets.only(bottom: 15.0),
- child: new MaterialButton(
- onPressed: _calculateClicked(),
- color: Colors.pink,
- child: new Text(
- "Calculate",
- style: new TextStyle(color: Colors.white),
- ),
- minWidth: 100.0,
- height: 45.0,
- )),
- ],
- )),
- new Padding(
- padding: EdgeInsets.only(top: 15.0),
- child: new Text("Your BMI: $bmi"),
- )
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement