Advertisement
Guest User

main

a guest
Nov 11th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.54 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:principal/CalculadoraController.dart';
  3.  
  4. void main() => runApp(MyApp());
  5.  
  6. class MyApp extends StatelessWidget {
  7.   // This widget is the root of your application.
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       title: 'CALCULADORA DE IMC',
  12.       theme: ThemeData(
  13.  
  14.         primarySwatch: Colors.blue,
  15.       ),
  16.       home: MyHomePage(),
  17.     );
  18.   }
  19. }
  20.  
  21. class MyHomePage extends StatefulWidget {
  22.   MyHomePage({Key key, this.title}) : super(key: key);
  23.  
  24.   final String title;
  25.  
  26.   @override
  27.   _MyHomePageState createState() => _MyHomePageState();
  28. }
  29.  
  30. class _MyHomePageState extends State<MyHomePage> {
  31.  
  32.   double _sliderVal = 100;
  33.  
  34.  
  35.   @override
  36.   Widget build(BuildContext context) {
  37.  
  38.     var tela = MediaQuery.of(context).size.width;
  39.  
  40.  
  41.     return  Scaffold(
  42.       backgroundColor: Colors.black87,
  43.       appBar: AppBar(
  44.         title: Text("Calculadora de IMC", style: TextStyle(fontSize: tela * .05),),
  45.         centerTitle: true,
  46.         backgroundColor: Colors.transparent,
  47.         elevation: 0.0,
  48.       ),
  49.       body: _body(context, tela),
  50.     );
  51.  
  52.   }
  53.  
  54.   Widget _body(context, tela){
  55.     return SingleChildScrollView(
  56.       child: StreamBuilder(
  57.         stream: calcBloc.outCalc,
  58.         builder: (context, snapshot) {
  59.           return Column(
  60.             children: <Widget>[
  61.               Padding(padding: EdgeInsets.only(top: tela * .08)),
  62.                 _generos(context, tela, snapshot.data["genero"]),
  63.               Padding(padding: EdgeInsets.only(top: tela * .08)),
  64.               _altura(context, tela, snapshot.data["altura"]),
  65.             ],
  66.           );
  67.         }
  68.       ),
  69.     );
  70.   }
  71.  
  72.   Widget _generos(context, tela, genero){
  73.     return Row(
  74.       mainAxisAlignment: MainAxisAlignment.spaceAround,
  75.       children: <Widget>[
  76.         GestureDetector(
  77.           onTap: (){
  78.             print("Clicado masculino");
  79.             calcBloc.alteraGenero("Masculino");
  80.           },
  81.           child: Container(
  82.             decoration:
  83.             BoxDecoration(
  84.               color: genero == "Masculino" ? Colors.blue : Colors.black12,
  85.               gradient: LinearGradient(colors: [Colors.blue, Colors.black12],
  86.               ),
  87.               border: Border.all(width: 2, color: Colors.white),
  88.               borderRadius: BorderRadius.all(Radius.circular(10.0)),
  89.             ),
  90.             child: Column(
  91.               children: <Widget>[
  92.                 Icon(Icons.trending_up, size: tela * .25, color: Colors.white,),
  93.                 Text("Masculino", style: TextStyle(fontSize: tela * .05, color: Colors.white),),
  94.  
  95.               ],
  96.             ),
  97.           ),
  98.         ),
  99.  
  100.         GestureDetector(
  101.           onTap: (){
  102.             print("Clicado feminino");
  103.             calcBloc.alteraGenero("Feminino");
  104.           },
  105.           child: Container(
  106.             decoration:
  107.             BoxDecoration(
  108.               color: genero == "Feminino" ? Colors.pink : Colors.black12,
  109.               gradient: LinearGradient(colors: [Colors.pink, Colors.black12],
  110.               ),
  111.               border: Border.all(width: 2, color: Colors.white),
  112.               borderRadius: BorderRadius.all(Radius.circular(10.0)),
  113.             ),
  114.             child: Column(
  115.               children: <Widget>[
  116.                 Icon(Icons.trending_down, size: tela * .25, color: Colors.white,),
  117.                 Text("Feminino", style: TextStyle(fontSize: tela * .05, color: Colors.white),),
  118.  
  119.               ],
  120.             ),
  121.           ),
  122.         ),
  123.       ],
  124.     );
  125.   }
  126.  
  127.  
  128.   Widget _altura(context, tela, altura){
  129.     return Container(
  130.       decoration: BoxDecoration(
  131.           color: Color.fromRGBO(0, 0, 199, .35),
  132.           borderRadius: BorderRadius.circular(10)
  133.       ),
  134.       padding: EdgeInsets.only(top: tela * .05, bottom: tela * .05),
  135.       child: Column(
  136.         children: <Widget>[
  137.           Text("Altura", style: TextStyle(color: Colors.white,  fontSize: tela *.04),),
  138.  
  139.  
  140.           Text(altura.toString(), style: TextStyle(color: Colors.white, fontSize: tela *.08),
  141.  
  142.           ),
  143.           Text("Centímetros", style: TextStyle(color: Colors.white,  fontSize: tela *.04),),
  144.           Slider(
  145.             value: _sliderVal,
  146.  
  147.             onChanged: (newRating) {
  148.               _sliderVal = newRating;
  149.               print(newRating);
  150.  
  151.  
  152.               calcBloc.addAltura(double.parse(newRating.toStringAsFixed(0)));
  153.              // _sliderVal = altura;
  154.             },
  155.             min: 0, max: 300,),
  156.         ],
  157.       ),
  158.     );
  159.  
  160.   }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement