From 0099dbdb1c8e04f9f69502d743f0721c6ec0eb51 Mon Sep 17 00:00:00 2001 From: wjrcode Date: Thu, 13 Oct 2022 21:15:25 -0300 Subject: [PATCH] Listas --- lib/Model/API/APIModel.dart | 3 +- .../dialogs/listas/listaCadastroDialog.dart | 53 ++++++++++++------- lib/components/input.dart | 24 ++++++--- 3 files changed, 52 insertions(+), 28 deletions(-) diff --git a/lib/Model/API/APIModel.dart b/lib/Model/API/APIModel.dart index 05f3173..45a7c22 100644 --- a/lib/Model/API/APIModel.dart +++ b/lib/Model/API/APIModel.dart @@ -1,5 +1,6 @@ class ApiModel { - static const ApiUrl = "http://10.0.0.91:4444"; + //static const ApiUrl = "http://10.0.0.91:4444"; + static const ApiUrl = "http://192.168.100.74:4444"; // static const ApiUrl = "http://189.10.2.165:4444"; static const String _token = "fd7bc88b7c0149adbc134d5d0a919814"; static const Map headers = { diff --git a/lib/components/dialogs/listas/listaCadastroDialog.dart b/lib/components/dialogs/listas/listaCadastroDialog.dart index 4e3df98..2d44002 100644 --- a/lib/components/dialogs/listas/listaCadastroDialog.dart +++ b/lib/components/dialogs/listas/listaCadastroDialog.dart @@ -6,13 +6,12 @@ import 'package:organizei/components/botao.dart'; import 'package:organizei/components/dialog_personalizado.dart'; import 'package:organizei/components/input.dart'; import 'package:organizei/components/selectCor.dart'; -import 'package:organizei/components/selectData.dart'; -import 'package:organizei/components/selectPrioridade.dart'; import '../../../Controller/ListaController.dart'; Future criarLista(BuildContext context, {ListaModel? lista = null, Function? fecharDialog = null}) { late ListaController listaController; + late List _controllers = [new TextEditingController()]; listaController = ListaController(ListaRepository(), context); @@ -63,18 +62,23 @@ Future criarLista(BuildContext context, shrinkWrap: true, itemCount: itens.length, itemBuilder: (context, index) { - var item; - //var dialog; - var controllerNomeItem = TextEditingController(); + // var controllerNomeItem = TextEditingController(); return Padding( padding: const EdgeInsets.only(bottom: 16), child: input( //onSaved: listaController.listaNome, - textController: controllerNomeItem, + textController: _controllers[index], label: 'item', + excluir: true, + funcao: () { + setState(() { + itens.remove(itens[index]); + _controllers.remove(_controllers[index]); + }); + }, ), ); }), @@ -86,6 +90,7 @@ Future criarLista(BuildContext context, clicar: () async { setState(() { itens.add(ItemModel()); + _controllers.add(new TextEditingController()); }); // bool succes = await listaController.saveLista(); @@ -103,23 +108,33 @@ Future criarLista(BuildContext context, }, ), ), - Botao( - texto: 'Salvar', - cor: const Color(0xFF6385C3), - clicar: () async { - bool succes = await listaController.saveLista(); + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: Botao( + texto: 'Salvar', + cor: const Color(0xFF6385C3), + clicar: () async { + List? listaitens = []; - if (succes == true) { - var nav = Navigator.of(context); - nav.pop(); + _controllers.map((item) { + listaitens.add(ItemModel(nome: (item.text))); + }).toList(); - if (lista?.id != null) { - //nav.pop(); + listaController.listaItens(listaitens); + bool succes = await listaController.saveLista(); + + if (succes == true) { + var nav = Navigator.of(context); nav.pop(); + + if (lista?.id != null) { + //nav.pop(); + nav.pop(); + } + fecharDialog!(); } - fecharDialog!(); - } - }, + }, + ), ), ], ), diff --git a/lib/components/input.dart b/lib/components/input.dart index 983d3f7..277cde2 100644 --- a/lib/components/input.dart +++ b/lib/components/input.dart @@ -1,13 +1,14 @@ import 'package:flutter/material.dart'; -Widget input({ - dynamic onSaved, - TextEditingController? textController, - String? label, - bool senha = false, - bool readOnly = false, - String? placeholder = '', -}) { +Widget input( + {dynamic onSaved, + TextEditingController? textController, + String? label, + bool senha = false, + bool readOnly = false, + String? placeholder = '', + bool excluir = false, + Function? funcao}) { return Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, @@ -28,6 +29,13 @@ Widget input({ onSaved: onSaved, controller: textController, decoration: InputDecoration( + suffixIcon: excluir + ? GestureDetector( + onTap: () { + funcao!(); + }, + child: const Icon(Icons.close)) + : null, hintText: placeholder, fillColor: Colors.white, filled: true,