Advertisement
joaopaulofcc

Untitled

Sep 30th, 2020
1,045
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 6.49 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.                 appBar: AppBar(
  40.                     title: Text('Produtos'),
  41.                     bottom: TabBar(tabs: [
  42.                       Tab(icon: Icon(Icons.add)),
  43.                       Tab(icon: Icon(Icons.view_agenda))
  44.                     ])),
  45.                 body: TabBarView(
  46.                   children: [
  47.                     Column(
  48.                       children: <Widget>[
  49.                         Padding(
  50.                             padding: const EdgeInsets.all(16.0),
  51.                             child: TextField(
  52.                                 controller: _controladorNome,
  53.                                 decoration:
  54.                                     InputDecoration(labelText: 'Nome'))),
  55.                         Padding(
  56.                             padding: const EdgeInsets.all(16.0),
  57.                             child: TextField(
  58.                               controller: _controladorQuantidade,
  59.                               decoration:
  60.                                   InputDecoration(labelText: 'Quantidade'),
  61.                               keyboardType: TextInputType.number,
  62.                             )),
  63.                         Padding(
  64.                             padding: const EdgeInsets.all(16.0),
  65.                             child: TextField(
  66.                               controller: _controladorValor,
  67.                               decoration: InputDecoration(labelText: 'Valor'),
  68.                               keyboardType: TextInputType.number,
  69.                             )),
  70.                         Padding(
  71.                           padding: const EdgeInsets.all(16.0),
  72.                           child: Row(
  73.                             children: [
  74.                               Expanded(
  75.                                   child: TextField(
  76.                                 controller: _controladorData,
  77.                                 enabled: false,
  78.                                 decoration: InputDecoration(labelText: 'Data'),
  79.                               )),
  80.                               Expanded(
  81.                                 child: RaisedButton(
  82.                                     child: Text('Selecionar Data'),
  83.                                     onPressed: () {
  84.                                       _selectDate(context);
  85.                                     }),
  86.                               )
  87.                             ],
  88.                           ),
  89.                         ),
  90.                         Padding(
  91.                             padding: const EdgeInsets.only(top: 16.0),
  92.                             child: RaisedButton(
  93.                               child: Text('Cadastrar'),
  94.                               onPressed: () {
  95.                                 final String nome = _controladorNome.text;
  96.                                 final int quantidade =
  97.                                     int.tryParse(_controladorQuantidade.text);
  98.                                 final double valor =
  99.                                     double.tryParse(_controladorValor.text);
  100.                                 final Produto produtoNovo = Produto(nome,
  101.                                     quantidade, valor, _controladorData.text);
  102.                                 print(produtoNovo);
  103.                               },
  104.                             )),
  105.                       ],
  106.                     ),
  107.                     SingleChildScrollView(
  108.                         scrollDirection: Axis.vertical,
  109.                         child: Center(
  110.                           child: Padding(
  111.                             padding: const EdgeInsets.only(top: 30.0),
  112.                             child: DataTable(
  113.                                 //sortAscending: sort,
  114.                                 //sortColumnIndex: 0,
  115.                                 columns: [
  116.                                   DataColumn(
  117.                                     label: Text("Nome",
  118.                                         style: TextStyle(fontSize: 16)),
  119.                                     numeric: false,
  120.                                   ),
  121.                                   DataColumn(
  122.                                     label: Text("Qtd",
  123.                                         style: TextStyle(fontSize: 16)),
  124.                                     numeric: true,
  125.                                   ),
  126.                                   DataColumn(
  127.                                     label: Text("Valor",
  128.                                         style: TextStyle(fontSize: 16)),
  129.                                     numeric: true,
  130.                                   ),
  131.                                   DataColumn(
  132.                                     label: Text("Data",
  133.                                         style: TextStyle(fontSize: 16)),
  134.                                     numeric: false,
  135.                                   ),
  136.                                 ], rows: [
  137.                               DataRow(cells: [
  138.                                 DataCell(Text("Arroz")),
  139.                                 DataCell(Text("30")),
  140.                                 DataCell(Text("15.75")),
  141.                                 DataCell(Text("20/05/2020")),
  142.                               ]),
  143.                             ]),
  144.                           ),
  145.                         ))
  146.                   ],
  147.                 ))));
  148.   }
  149. }
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement