From 5ac03a0d241b0abc88f642e95053f44766413e6b Mon Sep 17 00:00:00 2001 From: Willian <47341070+wjrcode@users.noreply.github.com> Date: Fri, 30 Sep 2022 17:51:49 -0300 Subject: [PATCH] select dia and habito dialog --- lib/Controller/TarefaController.dart | 38 +++++++ lib/Repository/TarefaRepository.dart | 8 ++ .../dialogs/tarefaCadastroDialog.dart | 14 +-- .../dialogs/tarefaCadastroHabito.dart | 107 ++++++++++++++++++ lib/components/dialogs/tarefaDialog.dart | 24 ++-- lib/components/navigation/menu.dart | 25 ++-- lib/components/selectCor.dart | 60 +++++----- lib/components/selectDias.dart | 88 ++++++++++++++ 8 files changed, 310 insertions(+), 54 deletions(-) create mode 100644 lib/components/dialogs/tarefaCadastroHabito.dart create mode 100644 lib/components/selectDias.dart diff --git a/lib/Controller/TarefaController.dart b/lib/Controller/TarefaController.dart index fa26d8b..cf686b7 100644 --- a/lib/Controller/TarefaController.dart +++ b/lib/Controller/TarefaController.dart @@ -149,4 +149,42 @@ class TarefaController extends Base { return false; } } + + Future excluirTarefa() async { + try { + return await repository.excluirTarefa(model).then((value) async { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + elevation: 6.0, + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + side: const BorderSide(color: Colors.black, width: 3), + borderRadius: BorderRadius.circular(16), + ), + content: Text( + value.msg!, + style: const TextStyle( + color: Colors.black, + fontWeight: FontWeight.w500, + ), + ), + backgroundColor: value.valido! + ? const Color(0xFF74C198) + : const Color(0xFFEF7E69), + ), + ); + + await Future.delayed(const Duration(milliseconds: 500)); + + if (value.valido!) { + return value.valido!; + } else { + return false; + } + }); + } catch (e) { + print(e); + return false; + } + } } diff --git a/lib/Repository/TarefaRepository.dart b/lib/Repository/TarefaRepository.dart index 29c4a4c..2414a39 100644 --- a/lib/Repository/TarefaRepository.dart +++ b/lib/Repository/TarefaRepository.dart @@ -54,6 +54,14 @@ class TarefaRepository { return ResponseAPIModel.fromJson(jsonDecode(response.body)); } + Future excluirTarefa(TarefaModel model) async { + final response = await http.delete( + Uri.parse(ApiModel.ApiUrl + '/tarefas/' + model.id.toString()), + headers: ApiModel.headers); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + Future> getTarefas() async { Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/tarefas'); diff --git a/lib/components/dialogs/tarefaCadastroDialog.dart b/lib/components/dialogs/tarefaCadastroDialog.dart index b7cae4a..f2be85c 100644 --- a/lib/components/dialogs/tarefaCadastroDialog.dart +++ b/lib/components/dialogs/tarefaCadastroDialog.dart @@ -7,13 +7,12 @@ 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 'package:organizei/home_page.dart'; import '../../Controller/TarefaController.dart'; Future criarTarefa(BuildContext context, {TarefaModel? tarefa = null, Function? fecharDialog = null}) { late TarefaController tarefaController; - //setState(() { + tarefaController = TarefaController(TarefaRepository(), context); if (tarefa != null) { @@ -25,8 +24,6 @@ Future criarTarefa(BuildContext context, tarefaController.tarefaId(tarefa.id); } - // }); - return showDialog( barrierDismissible: false, barrierColor: Colors.white.withOpacity(0), @@ -66,9 +63,12 @@ Future criarTarefa(BuildContext context, label: 'observação', ), ), - SelectPrioridade( - prioridade: tarefaController.tarefaPrioridade, - prioridadeAtual: tarefa?.prioridade ?? ''), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: SelectPrioridade( + prioridade: tarefaController.tarefaPrioridade, + prioridadeAtual: tarefa?.prioridade ?? ''), + ), SelectCor( cor: tarefaController.tarefaCor, corAtual: tarefa?.cor ?? ''), diff --git a/lib/components/dialogs/tarefaCadastroHabito.dart b/lib/components/dialogs/tarefaCadastroHabito.dart new file mode 100644 index 0000000..e007620 --- /dev/null +++ b/lib/components/dialogs/tarefaCadastroHabito.dart @@ -0,0 +1,107 @@ +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/input.dart'; +import 'package:organizei/components/selectCor.dart'; +import 'package:organizei/components/selectData.dart'; +import 'package:organizei/components/selectDias.dart'; +import 'package:organizei/components/selectPrioridade.dart'; +import 'package:organizei/home_page.dart'; +import '../../Controller/TarefaController.dart'; + +Future criarHabito(BuildContext context, + {TarefaModel? tarefa = null, Function? fecharDialog = null}) { + late TarefaController tarefaController; + + tarefaController = TarefaController(TarefaRepository(), context); + + if (tarefa != null) { + tarefaController.controllerNome.text = tarefa.nome ?? ''; + tarefaController.controllerDataehora.text = tarefa.data ?? ''; + tarefaController.controllerObservacao.text = tarefa.observacao ?? ''; + tarefaController.tarefaPrioridade(tarefa.prioridade); + tarefaController.tarefaCor(tarefa.cor); + 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( + margin: const EdgeInsets.only(top: 24), + child: DialogPersonalizado( + nome: 'Hábito', + child: [ + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: tarefaController.tarefaNome, + textController: tarefaController.controllerNome, + label: 'nome', + ), + ), + SelectData( + controller: tarefaController.controllerDataehora, + onSaved: tarefaController.tarefaDataehora), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: tarefaController.tarefaObservacao, + textController: + tarefaController.controllerObservacao, + label: 'observação', + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: SelectPrioridade( + prioridade: tarefaController.tarefaPrioridade, + prioridadeAtual: tarefa?.prioridade ?? ''), + ), + SelectDia(dia: tarefaController.tarefaCor), + SelectCor( + cor: tarefaController.tarefaCor, + corAtual: tarefa?.cor ?? ''), + Botao( + texto: 'Salvar', + cor: const Color(0xFF6385C3), + clicar: () async { + bool succes = await tarefaController.saveTarefa(); + + if (succes == true) { + var nav = Navigator.of(context); + nav.pop(); + + if (tarefa?.id != null) { + //nav.pop(); + nav.pop(); + } + fecharDialog!(); + } + }, + ), + ], + ), + ), + ), + ), + ), + ); + }); + }); +} + +selectDias() {} diff --git a/lib/components/dialogs/tarefaDialog.dart b/lib/components/dialogs/tarefaDialog.dart index 9748290..0e65bad 100644 --- a/lib/components/dialogs/tarefaDialog.dart +++ b/lib/components/dialogs/tarefaDialog.dart @@ -83,18 +83,26 @@ Future visualizarTarefa(BuildContext context, texto: 'Editar', cor: const Color(0xFF6385C3), clicar: () async { - // Navigator.pop(context); criarTarefa(context, tarefa: tarefa, fecharDialog: fecharDialog); - - // bool succes = await tarefaController.saveTarefa(); - - // if (succes == true) { - // Navigator.pop(context); - // 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 396f5e2..8a8881e 100644 --- a/lib/components/navigation/menu.dart +++ b/lib/components/navigation/menu.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:organizei/components/dialog_personalizado.dart'; import 'package:organizei/components/dialogs/tarefaCadastroDialog.dart'; +import 'package:organizei/components/dialogs/tarefaCadastroHabito.dart'; class Menu extends StatefulWidget { const Menu({Key? key, this.fecharMenu, this.fecharDialog = null}) @@ -191,15 +192,23 @@ class _MenuState extends State { thickness: 3, color: Colors.black, ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'criar hábito', - style: TextStyle(fontSize: 24.0), + GestureDetector( + onTap: () { + criarHabito(context); + widget.fecharMenu!(); + }, + child: AbsorbPointer( + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + 'criar hábito', + style: TextStyle(fontSize: 24.0), + ), + ], ), - ], + ), ), Divider( thickness: 3, diff --git a/lib/components/selectCor.dart b/lib/components/selectCor.dart index 2fcb652..ad75a0a 100644 --- a/lib/components/selectCor.dart +++ b/lib/components/selectCor.dart @@ -45,37 +45,35 @@ class _SelectCorState extends State { ), Padding( padding: const EdgeInsets.only(bottom: 16), - child: Expanded( - child: SizedBox( - height: 50, - child: ListView( - itemExtent: 70.0, - scrollDirection: Axis.horizontal, - children: cores.map((strone) { - return GestureDetector( - onTap: () { - setState(() { - corSelected = strone; - }); - widget.cor(corSelected.toString()); - }, - child: Container( - width: 60, - height: 60, - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Color(strone), - border: Border.all( - width: corSelected == strone ? 5 : 3, - color: corSelected == strone - ? Colors.white - : Colors.black, - style: BorderStyle.solid, - )), - ), - ); - }).toList(), - ), + child: SizedBox( + height: 50, + child: ListView( + itemExtent: 70.0, + scrollDirection: Axis.horizontal, + children: cores.map((strone) { + return GestureDetector( + onTap: () { + setState(() { + corSelected = strone; + }); + widget.cor(corSelected.toString()); + }, + child: Container( + width: 60, + height: 60, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Color(strone), + border: Border.all( + width: corSelected == strone ? 5 : 3, + color: corSelected == strone + ? Colors.white + : Colors.black, + style: BorderStyle.solid, + )), + ), + ); + }).toList(), ), )), ], diff --git a/lib/components/selectDias.dart b/lib/components/selectDias.dart new file mode 100644 index 0000000..a23ed38 --- /dev/null +++ b/lib/components/selectDias.dart @@ -0,0 +1,88 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Controller/TarefaController.dart'; + +class SelectDia extends StatefulWidget { + final dynamic dia; + final String diaAtual; + const SelectDia({Key? key, required this.dia, this.diaAtual = ''}) + : super(key: key); + + @override + State createState() => _SelectDiaState(); +} + +class _SelectDiaState extends State { + List dias = ['D', 'S', 'T', 'Q', 'Q', 'S', 'S']; + + late String diaSelected = ''; + + @override + void initState() { + super.initState(); + diaSelected = widget.diaAtual; + } + + @override + Widget build(BuildContext context) { + return Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'dia', + style: TextStyle( + color: Colors.black, + fontSize: 16, + fontWeight: FontWeight.w400, + ), + ), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: SizedBox( + height: 50, + child: ListView( + itemExtent: 50.0, + scrollDirection: Axis.horizontal, + children: dias.map((dia) { + return GestureDetector( + onTap: () { + setState(() { + diaSelected = dia; + }); + widget.dia(diaSelected.toString()); + }, + child: Container( + width: 20, + height: 20, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: Color(0xFFE9E9E9), + border: Border.all( + width: 3, + color: Colors.black, + style: BorderStyle.solid, + )), + child: Align( + alignment: Alignment.center, + child: Text( + dia, + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.w700, + ), + ), + ) + // ),Text( + // dia, + // textAlign: TextAlign.center, + // ), + ), + ); + }).toList(), + ), + )), + ], + ); + } +}