Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'Models/Produto.dart';
- void main() => runApp(Mercado());
- class Mercado extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: "Mercado",
- home: MyApp(),
- );
- }
- }
- class MyApp extends StatelessWidget {
- final TextEditingController _controladorNome = TextEditingController();
- final TextEditingController _controladorQuantidade = TextEditingController();
- final TextEditingController _controladorValor = TextEditingController();
- final TextEditingController _controladorData = TextEditingController();
- Future<void> _selectDate(context) async {
- DateTime selectedDate = await showDatePicker(
- context: context,
- initialDate: DateTime.now(),
- firstDate: DateTime(2017),
- lastDate: DateTime(2021));
- String resultado =
- "${selectedDate.day}/${selectedDate.month}/${selectedDate.year}";
- _controladorData.text = resultado;
- }
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: DefaultTabController(
- length: 2,
- child: Scaffold(
- resizeToAvoidBottomPadding: false,
- appBar: AppBar(
- title: Text('Produtos'),
- bottom: TabBar(tabs: [
- Tab(icon: Icon(Icons.add)),
- Tab(icon: Icon(Icons.table_chart))
- ])),
- body: TabBarView(
- children: [
- Column(
- children: <Widget>[
- Padding(
- padding: const EdgeInsets.all(16.0),
- child: TextField(
- controller: _controladorNome,
- decoration:
- InputDecoration(labelText: 'Nome'))),
- Padding(
- padding: const EdgeInsets.all(16.0),
- child: TextField(
- controller: _controladorQuantidade,
- decoration:
- InputDecoration(labelText: 'Quantidade'),
- keyboardType: TextInputType.number,
- )),
- Padding(
- padding: const EdgeInsets.all(16.0),
- child: TextField(
- controller: _controladorValor,
- decoration: InputDecoration(labelText: 'Valor'),
- keyboardType: TextInputType.number,
- )),
- Padding(
- padding: const EdgeInsets.all(16.0),
- child: Row(
- children: [
- Expanded(
- child: TextField(
- controller: _controladorData,
- enabled: false,
- decoration: InputDecoration(labelText: 'Data'),
- )),
- Expanded(
- child: RaisedButton(
- child: Text('Selecionar Data'),
- onPressed: () {
- _selectDate(context);
- }),
- )
- ],
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(top: 16.0),
- child: RaisedButton(
- child: Text('Cadastrar'),
- onPressed: () {
- final String nome = _controladorNome.text;
- final int quantidade =
- int.tryParse(_controladorQuantidade.text);
- final double valor =
- double.tryParse(_controladorValor.text);
- final Produto produtoNovo = Produto(nome,
- quantidade, valor, _controladorData.text);
- print(produtoNovo);
- },
- )),
- ],
- ),
- SingleChildScrollView(
- scrollDirection: Axis.vertical,
- child: Center(
- child: Padding(
- padding: const EdgeInsets.only(top: 30.0),
- child: DataTable(
- //sortAscending: sort,
- //sortColumnIndex: 0,
- columns: [
- DataColumn(
- label: Text("Nome",
- style: TextStyle(fontSize: 16)),
- numeric: false,
- ),
- DataColumn(
- label: Text("Qtd",
- style: TextStyle(fontSize: 16)),
- numeric: true,
- ),
- DataColumn(
- label: Text("Valor",
- style: TextStyle(fontSize: 16)),
- numeric: true,
- ),
- DataColumn(
- label: Text("Data",
- style: TextStyle(fontSize: 16)),
- numeric: false,
- ),
- ], rows: [
- DataRow(cells: [
- DataCell(Text("Arroz")),
- DataCell(Text("30")),
- DataCell(Text("15.75")),
- DataCell(Text("20/05/2020")),
- ]),
- ]),
- ),
- ))
- ],
- ))));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement