From 311c6adcda147710ffb0211d2572d5cb6f842d14 Mon Sep 17 00:00:00 2001 From: wjrcode Date: Sat, 15 Oct 2022 18:41:16 -0300 Subject: [PATCH] lembretes --- lib/Controller/LembreteController.dart | 40 ++++++++++++++ lib/Repository/LembreteRepository.dart | 17 ++++++ .../lembretes/lembreteCadastroDialog.dart | 5 +- .../dialogs/lembretes/lembreteDialog.dart | 53 +++++++------------ lib/home_page.dart | 15 ++++++ 5 files changed, 93 insertions(+), 37 deletions(-) diff --git a/lib/Controller/LembreteController.dart b/lib/Controller/LembreteController.dart index 85a138e..f8fc8d9 100644 --- a/lib/Controller/LembreteController.dart +++ b/lib/Controller/LembreteController.dart @@ -111,6 +111,46 @@ class LembreteController extends Base { return await repository.get(); } + Future concluirLembrete(bool concluido) async { + try { + return await repository + .concluirLembrete(model, concluido) + .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; + } + } + Future excluirLembrete() async { try { return await repository.excluirLembrete(model).then((value) async { diff --git a/lib/Repository/LembreteRepository.dart b/lib/Repository/LembreteRepository.dart index d4b7195..b1540f0 100644 --- a/lib/Repository/LembreteRepository.dart +++ b/lib/Repository/LembreteRepository.dart @@ -59,6 +59,23 @@ class LembreteRepository { return listaLembretes; } + Future concluirLembrete( + LembreteModel model, bool concluido) async { + var json = { + "concluido": concluido, + }; + + final response = await http.put( + Uri.parse(ApiModel.ApiUrl + + '/lembretes/' + + model.id.toString() + + '/concluir'), + headers: ApiModel.headers, + body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + Future> get() async { Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes'); diff --git a/lib/components/dialogs/lembretes/lembreteCadastroDialog.dart b/lib/components/dialogs/lembretes/lembreteCadastroDialog.dart index cc163d6..a822fef 100644 --- a/lib/components/dialogs/lembretes/lembreteCadastroDialog.dart +++ b/lib/components/dialogs/lembretes/lembreteCadastroDialog.dart @@ -77,9 +77,6 @@ Future criarLembrete(BuildContext context, setState(() { eAniversario = value; }); - - lembreteController - .lembreteAniversario(eAniversario); }, ), ), @@ -96,6 +93,8 @@ Future criarLembrete(BuildContext context, texto: 'Salvar', cor: const Color(0xFF6385C3), clicar: () async { + lembreteController + .lembreteAniversario(eAniversario); bool succes = await lembreteController.saveLembrete(); diff --git a/lib/components/dialogs/lembretes/lembreteDialog.dart b/lib/components/dialogs/lembretes/lembreteDialog.dart index a6e4fde..36fcea0 100644 --- a/lib/components/dialogs/lembretes/lembreteDialog.dart +++ b/lib/components/dialogs/lembretes/lembreteDialog.dart @@ -1,17 +1,17 @@ import 'package:flutter/material.dart'; -import 'package:organizei/Model/Tarefa/TarefaModel.dart'; -import 'package:organizei/Repository/TarefaRepository.dart'; +import 'package:organizei/Model/Lembrete/LembreteModel.dart'; +import 'package:organizei/Repository/LembreteRepository.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'; +import 'package:organizei/components/dialogs/lembretes/lembreteCadastroDialog.dart'; +import '../../../Controller/LembreteController.dart'; -Future visualizarTarefa(BuildContext context, - {required TarefaModel tarefa, Function? fecharDialog = null}) { - late TarefaController tarefaController; - tarefaController = TarefaController(TarefaRepository(), context); +Future visualizarLembrete(BuildContext context, + {required LembreteModel lembrete, Function? fecharDialog = null}) { + late LembreteController lembreteController; + lembreteController = LembreteController(LembreteRepository(), context); - tarefaController.tarefaId(tarefa.id); + lembreteController.lembreteId(lembrete.id); return showDialog( barrierDismissible: false, @@ -26,7 +26,7 @@ Future visualizarTarefa(BuildContext context, child: Material( type: MaterialType.transparency, child: Form( - key: tarefaController.formKey, + key: lembreteController.formKey, child: Padding( padding: const EdgeInsets.only(top: 24.0), child: ConstrainedBox( @@ -34,10 +34,9 @@ Future visualizarTarefa(BuildContext context, minHeight: MediaQuery.of(context).size.height, ), child: DialogPersonalizado( - nome: tarefa.nome ?? '', - cor: tarefa.cor ?? '', + nome: lembrete.nome ?? '', + cor: lembrete.cor ?? '', child: [ - Text(tarefa.observacao ?? ''), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, @@ -49,21 +48,7 @@ Future visualizarTarefa(BuildContext context, 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 ?? ''), + Text(lembrete.data ?? ''), ], ), Padding( @@ -72,9 +57,8 @@ Future visualizarTarefa(BuildContext context, texto: 'Concluir', cor: const Color(0xFF74C198), clicar: () async { - bool succes = - await tarefaController.concluirTarefa(true); - + bool succes = await lembreteController + .concluirLembrete(true); if (succes == true) { Navigator.pop(context); fecharDialog!(); @@ -86,8 +70,9 @@ Future visualizarTarefa(BuildContext context, texto: 'Editar', cor: const Color(0xFF6385C3), clicar: () async { - criarTarefa(context, - tarefa: tarefa, fecharDialog: fecharDialog); + criarLembrete(context, + lembrete: lembrete, + fecharDialog: fecharDialog); }, ), Padding( @@ -97,7 +82,7 @@ Future visualizarTarefa(BuildContext context, cor: const Color(0xFFEF7E69), clicar: () async { bool succes = - await tarefaController.excluirTarefa(); + await lembreteController.excluirLembrete(); if (succes == true) { Navigator.pop(context); diff --git a/lib/home_page.dart b/lib/home_page.dart index 35bacde..003ee5b 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -3,11 +3,13 @@ import 'package:http/retry.dart'; import 'package:intl/date_symbol_data_local.dart'; import 'package:organizei/Controller/TarefaController.dart'; import 'package:organizei/Model/Habito/HabitoModel.dart'; +import 'package:organizei/Model/Lembrete/LembreteModel.dart'; import 'package:organizei/Model/Tarefa/TarefaModel.dart'; import 'package:organizei/Repository/TarefaRepository.dart'; import 'package:organizei/components/card_item.dart'; import 'package:intl/intl.dart'; import 'package:organizei/components/dialogs/habitos/habitoDialog.dart'; +import 'package:organizei/components/dialogs/lembretes/lembreteDialog.dart'; import 'package:organizei/components/dialogs/tarefas/tarefaDialog.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -198,6 +200,11 @@ class _HomePageState extends State { item = HabitoModel.fromJson( snapshot.data['tarefas'][index]); } + + if (tipo == 'lembrete') { + item = LembreteModel.fromJson( + snapshot.data['tarefas'][index]); + } return cardItem( cor: Color(int.tryParse( item.cor ?? '0xFF6385C3') ?? @@ -222,6 +229,14 @@ class _HomePageState extends State { setState(() {}); }, ); + } else if (tipo == 'lembrete') { + return visualizarLembrete( + context, + lembrete: item, + fecharDialog: () { + setState(() {}); + }, + ); } }); });