From 43e074d18eb660cd196a73f7fd7d462537260ea1 Mon Sep 17 00:00:00 2001 From: Willian <47341070+wjrcode@users.noreply.github.com> Date: Thu, 13 Oct 2022 17:56:39 -0300 Subject: [PATCH] Listas --- .../dialogs/listas/listaCadastroDialog.dart | 133 ++++++++++++++++++ .../dialogs/listas/listaDialog.dart | 115 +++++++++++++++ lib/components/navigation/menu.dart | 111 +-------------- 3 files changed, 250 insertions(+), 109 deletions(-) create mode 100644 lib/components/dialogs/listas/listaCadastroDialog.dart create mode 100644 lib/components/dialogs/listas/listaDialog.dart diff --git a/lib/components/dialogs/listas/listaCadastroDialog.dart b/lib/components/dialogs/listas/listaCadastroDialog.dart new file mode 100644 index 0000000..4e3df98 --- /dev/null +++ b/lib/components/dialogs/listas/listaCadastroDialog.dart @@ -0,0 +1,133 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Model/Item/ItemModel.dart'; +import 'package:organizei/Model/Lista/ListaModel.dart'; +import 'package:organizei/Repository/ListaRepository.dart'; +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; + + listaController = ListaController(ListaRepository(), context); + + late List? itens = [ItemModel()]; + + if (lista != null) { + listaController.controllerNome.text = lista.nome ?? ''; + listaController.listaCor(lista.cor); + listaController.listaId(lista.id); + listaController.listaItens(lista.itens); + } + + return showDialog( + barrierDismissible: false, + barrierColor: Colors.white.withOpacity(0), + context: context, + builder: (context) { + return StatefulBuilder(builder: (context, StateSetter setState) { + return Scaffold( + backgroundColor: Colors.transparent, + body: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Material( + type: MaterialType.transparency, + child: Form( + key: listaController.formKey, + child: Container( + margin: const EdgeInsets.only(top: 24), + height: itens.length < 3 + ? MediaQuery.of(context).size.height + : null, + child: DialogPersonalizado( + nome: 'Lista', + child: [ + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: listaController.listaNome, + textController: listaController.controllerNome, + label: 'nome', + ), + ), + SelectCor( + cor: listaController.listaCor, + corAtual: lista?.cor ?? ''), + ListView.builder( + primary: false, + shrinkWrap: true, + itemCount: itens.length, + itemBuilder: (context, index) { + var item; + + //var dialog; + + var controllerNomeItem = TextEditingController(); + + return Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + //onSaved: listaController.listaNome, + textController: controllerNomeItem, + label: 'item', + ), + ); + }), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: Botao( + texto: 'Novo item', + cor: const Color(0xFF6BC8E4), + clicar: () async { + setState(() { + itens.add(ItemModel()); + }); + + // bool succes = await listaController.saveLista(); + + // if (succes == true) { + // var nav = Navigator.of(context); + // nav.pop(); + + // if (lista?.id != null) { + // //nav.pop(); + // nav.pop(); + // } + // fecharDialog!(); + // } + }, + ), + ), + Botao( + texto: 'Salvar', + cor: const Color(0xFF6385C3), + clicar: () async { + bool succes = await listaController.saveLista(); + + if (succes == true) { + var nav = Navigator.of(context); + nav.pop(); + + if (lista?.id != null) { + //nav.pop(); + nav.pop(); + } + fecharDialog!(); + } + }, + ), + ], + ), + ), + ), + ), + ), + ); + }); + }); +} diff --git a/lib/components/dialogs/listas/listaDialog.dart b/lib/components/dialogs/listas/listaDialog.dart new file mode 100644 index 0000000..d8e7e11 --- /dev/null +++ b/lib/components/dialogs/listas/listaDialog.dart @@ -0,0 +1,115 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Model/Tarefa/TarefaModel.dart'; +import 'package:organizei/Repository/TarefaRepository.dart'; +import 'package:organizei/components/botao.dart'; +import 'package:organizei/components/dialog_personalizado.dart'; +import 'package:organizei/components/dialogs/tarefas/tarefaCadastroDialog.dart'; +import '../../../Controller/TarefaController.dart'; + +Future visualizarTarefa(BuildContext context, + {required TarefaModel tarefa, Function? fecharDialog = null}) { + late TarefaController tarefaController; + tarefaController = TarefaController(TarefaRepository(), context); + + tarefaController.tarefaId(tarefa.id); + + return showDialog( + barrierDismissible: false, + barrierColor: Colors.white.withOpacity(0), + context: context, + builder: (context) { + return StatefulBuilder(builder: (context, StateSetter setState) { + return Scaffold( + backgroundColor: Colors.transparent, + body: SingleChildScrollView( + scrollDirection: Axis.vertical, + child: Material( + type: MaterialType.transparency, + child: Form( + key: tarefaController.formKey, + child: Container( + height: MediaQuery.of(context).size.height, + margin: const EdgeInsets.only(top: 24), + child: DialogPersonalizado( + nome: tarefa.nome ?? '', + cor: tarefa.cor ?? '', + child: [ + Text(tarefa.observacao ?? ''), + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Text( + 'data: ', + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w700, + ), + ), + Text(tarefa.data ?? ''), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const Text( + 'prioridade: ', + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w700, + ), + ), + Text(tarefa.prioridade ?? ''), + ], + ), + Padding( + padding: const EdgeInsets.only(bottom: 16, top: 16), + child: Botao( + texto: 'Concluir', + cor: const Color(0xFF74C198), + clicar: () async { + bool succes = + await tarefaController.concluirTarefa(true); + + if (succes == true) { + Navigator.pop(context); + fecharDialog!(); + } + }, + ), + ), + Botao( + texto: 'Editar', + cor: const Color(0xFF6385C3), + clicar: () async { + criarTarefa(context, + tarefa: tarefa, fecharDialog: fecharDialog); + }, + ), + Padding( + padding: const EdgeInsets.only(bottom: 16, top: 16), + child: Botao( + texto: 'Excluir', + cor: const Color(0xFFEF7E69), + clicar: () async { + bool succes = + await tarefaController.excluirTarefa(); + + if (succes == true) { + Navigator.pop(context); + fecharDialog!(); + } + }, + ), + ), + ], + ), + ), + ), + ), + ), + ); + }); + }); +} diff --git a/lib/components/navigation/menu.dart b/lib/components/navigation/menu.dart index a7e4103..cc3f20a 100644 --- a/lib/components/navigation/menu.dart +++ b/lib/components/navigation/menu.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:organizei/components/dialog_personalizado.dart'; +import 'package:organizei/components/dialogs/listas/listaCadastroDialog.dart'; import 'package:organizei/components/dialogs/tarefas/tarefaCadastroDialog.dart'; import 'package:organizei/components/dialogs/habitos/habitoCadastroDialog.dart'; @@ -42,118 +43,10 @@ class _MenuState extends State { children: [ GestureDetector( onTap: () { + criarLista(context, fecharDialog: widget.fecharDialog); widget.fecharMenu!(); - showDialog( - barrierDismissible: false, - barrierColor: Colors.white.withOpacity(0), - context: context, - builder: (context) { - return Container( - margin: EdgeInsets.only(top: 24), - child: DialogPersonalizado( - nome: 'Lista', - //minHeight: MediaQuery.of(context).size.height * 0.8, - child: [ - Text( - 'nome', - style: const TextStyle( - color: Colors.black, - fontSize: 16, - fontWeight: FontWeight.w400, - ), - ), - Material( - color: Colors.white.withOpacity(0), - child: TextField( - decoration: InputDecoration( - fillColor: Colors.white, - filled: true, - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Colors.black, - width: 3.0, - ), - borderRadius: BorderRadius.circular(16.0), - ), - focusedBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Colors.black, - width: 3.0, - ), - borderRadius: BorderRadius.circular(16.0), - ), - - //labelText: 'Password', - ), - ), - ), - Text( - 'item', - style: const TextStyle( - color: Colors.black, - fontSize: 16, - fontWeight: FontWeight.w400, - ), - ), - Material( - color: Colors.white.withOpacity(0), - child: TextField( - decoration: InputDecoration( - fillColor: Colors.white, - filled: true, - enabledBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Colors.black, - width: 3.0, - ), - borderRadius: BorderRadius.circular(16.0), - ), - focusedBorder: OutlineInputBorder( - borderSide: const BorderSide( - color: Colors.black, - width: 3.0, - ), - borderRadius: BorderRadius.circular(16.0), - ), - - //labelText: 'Password', - ), - ), - ), - SizedBox( - width: double.maxFinite, - height: 60, - child: ElevatedButton( - style: ButtonStyle( - shape: MaterialStateProperty.all< - RoundedRectangleBorder>( - RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(16.0), - // side: BorderSide(color: Colors.red) - )), - side: MaterialStateProperty.all( - BorderSide( - width: 3, color: Colors.black)), - backgroundColor: - MaterialStateProperty.all( - Color(0xFF6385C3)), - ), - child: Text( - 'SALVAR', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold), - ), - onPressed: () {}), - ), - ], - ), - ); - }); }, child: AbsorbPointer( - //width: MediaQuery.of(context).size.width, child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,