Advertisement
joaopaulofcc

Untitled

Sep 30th, 2020
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 6.54 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'Models/Produto.dart';
  3.  
  4. void main() => runApp(Mercado());
  5.  
  6. class Mercado extends StatelessWidget {
  7.   @override
  8.   Widget build(BuildContext context) {
  9.     return MaterialApp(
  10.       title: "Mercado",
  11.       home: MyApp(),
  12.     );
  13.   }
  14. }
  15.  
  16. class MyApp extends StatelessWidget {
  17.   final TextEditingController _controladorNome = TextEditingController();
  18.   final TextEditingController _controladorQuantidade = TextEditingController();
  19.   final TextEditingController _controladorValor = TextEditingController();
  20.   final TextEditingController _controladorData = TextEditingController();
  21.  
  22.   Future<void> _selectDate(context) async {
  23.     DateTime selectedDate = await showDatePicker(
  24.         context: context,
  25.         initialDate: DateTime.now(),
  26.         firstDate: DateTime(2017),
  27.         lastDate: DateTime(2021));
  28.     String resultado =
  29.         "${selectedDate.day}/${selectedDate.month}/${selectedDate.year}";
  30.     _controladorData.text = resultado;
  31.   }
  32.  
  33.   @override
  34.   Widget build(BuildContext context) {
  35.     return MaterialApp(
  36.         home: DefaultTabController(
  37.             length: 2,
  38.             child: Scaffold(
  39.                 resizeToAvoidBottomPadding: false,
  40.                 appBar: AppBar(
  41.                     title: Text('Produtos'),
  42.                     bottom: TabBar(tabs: [
  43.                       Tab(icon: Icon(Icons.add)),
  44.                       Tab(icon: Icon(Icons.table_chart))
  45.                     ])),
  46.                 body: TabBarView(
  47.                   children: [
  48.                     Column(
  49.                       children: <Widget>[
  50.                         Padding(
  51.                             padding: const EdgeInsets.all(16.0),
  52.                             child: TextField(
  53.                                 controller: _controladorNome,
  54.                                 decoration:
  55.                                     InputDecoration(labelText: 'Nome'))),
  56.                         Padding(
  57.                             padding: const EdgeInsets.all(16.0),
  58.                             child: TextField(
  59.                               controller: _controladorQuantidade,
  60.                               decoration:
  61.                                   InputDecoration(labelText: 'Quantidade'),
  62.                               keyboardType: TextInputType.number,
  63.                             )),
  64.                         Padding(
  65.                             padding: const EdgeInsets.all(16.0),
  66.                             child: TextField(
  67.                               controller: _controladorValor,
  68.                               decoration: InputDecoration(labelText: 'Valor'),
  69.                               keyboardType: TextInputType.number,
  70.                             )),
  71.                         Padding(
  72.                           padding: const EdgeInsets.all(16.0),
  73.                           child: Row(
  74.                             children: [
  75.                               Expanded(
  76.                                   child: TextField(
  77.                                 controller: _controladorData,
  78.                                 enabled: false,
  79.                                 decoration: InputDecoration(labelText: 'Data'),
  80.                               )),
  81.                               Expanded(
  82.                                 child: RaisedButton(
  83.                                     child: Text('Selecionar Data'),
  84.                                     onPressed: () {
  85.                                       _selectDate(context);
  86.                                     }),
  87.                               )
  88.                             ],
  89.                           ),
  90.                         ),
  91.                         Padding(
  92.                             padding: const EdgeInsets.only(top: 16.0),
  93.                             child: RaisedButton(
  94.                               child: Text('Cadastrar'),
  95.                               onPressed: () {
  96.                                 final String nome = _controladorNome.text;
  97.                                 final int quantidade =
  98.                                     int.tryParse(_controladorQuantidade.text);
  99.                                 final double valor =
  100.                                     double.tryParse(_controladorValor.text);
  101.                                 final Produto produtoNovo = Produto(nome,
  102.                                     quantidade, valor, _controladorData.text);
  103.                                 print(produtoNovo);
  104.                               },
  105.                             )),
  106.                       ],
  107.                     ),
  108.                     SingleChildScrollView(
  109.                         scrollDirection: Axis.vertical,
  110.                         child: Center(
  111.                           child: Padding(
  112.                             padding: const EdgeInsets.only(top: 30.0),
  113.                             child: DataTable(
  114.                                 //sortAscending: sort,
  115.                                 //sortColumnIndex: 0,
  116.                                 columns: [
  117.                                   DataColumn(
  118.                                     label: Text("Nome",
  119.                                         style: TextStyle(fontSize: 16)),
  120.                                     numeric: false,
  121.                                   ),
  122.                                   DataColumn(
  123.                                     label: Text("Qtd",
  124.                                         style: TextStyle(fontSize: 16)),
  125.                                     numeric: true,
  126.                                   ),
  127.                                   DataColumn(
  128.                                     label: Text("Valor",
  129.                                         style: TextStyle(fontSize: 16)),
  130.                                     numeric: true,
  131.                                   ),
  132.                                   DataColumn(
  133.                                     label: Text("Data",
  134.                                         style: TextStyle(fontSize: 16)),
  135.                                     numeric: false,
  136.                                   ),
  137.                                 ], rows: [
  138.                               DataRow(cells: [
  139.                                 DataCell(Text("Arroz")),
  140.                                 DataCell(Text("30")),
  141.                                 DataCell(Text("15.75")),
  142.                                 DataCell(Text("20/05/2020")),
  143.                               ]),
  144.                             ]),
  145.                           ),
  146.                         ))
  147.                   ],
  148.                 ))));
  149.   }
  150. }
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement