diff --git a/lib/Controller/ProjetoController.dart b/lib/Controller/ProjetoController.dart new file mode 100644 index 0000000..1b94879 --- /dev/null +++ b/lib/Controller/ProjetoController.dart @@ -0,0 +1,191 @@ +import 'dart:ffi'; + +import 'package:flutter/material.dart'; +import 'package:http/http.dart'; +import 'package:organizei/Model/Projeto/ProjetoModel.dart'; +import 'package:organizei/Controller/Base/Base.dart'; +import 'package:organizei/Repository/ProjetoRepository.dart'; +import 'package:organizei/services/persistencia/login.configuracoes.dart'; + +class ProjetoController extends Base { + ProjetoController(this.repository, this.context); + + final BuildContext context; + final ProjetoRepository repository; + final formKey = GlobalKey(); + var model = ProjetoModel(); + //var loginConfiguracoes = LoginConfiguracoes(); + + projetoId(int? value) => model.id = value; + projetoNome(String? value) => model.nome = value.toString(); + projetoDataInical(String? value) => model.dataInicial = value.toString(); + projetoObservacao(String? value) => model.observacao = value.toString(); + projetoDataFinal(String? value) => model.dataFinal = value.toString(); + projetoCor(String? value) => model.cor = value.toString(); + + var controllerNome = TextEditingController(); + var controllerObservacao = TextEditingController(); + var controllerPrioridade = TextEditingController(); + var controllerCor = TextEditingController(); + var controllerDataIncial = TextEditingController(); + var controllerDataFinal = TextEditingController(); + + Future saveProjeto() async { + if (!formKey.currentState!.validate()) { + return false; + } + + formKey.currentState!.save(); + + try { + if (model.id == null) { + return await repository.addProjeto(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; + } + }); + } else { + return await repository.updateProjeto(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; + } + } + + Future> getProjetos() async { + return await repository.getProjetos(); + } + + Future concluirProjeto(bool concluido) async { + try { + return await repository + .concluirProjeto(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 excluirProjeto() async { + try { + return await repository.excluirProjeto(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/Model/Login/LoginModel.dart b/lib/Model/Login/LoginModel.dart index 8fcb522..a9c4def 100644 --- a/lib/Model/Login/LoginModel.dart +++ b/lib/Model/Login/LoginModel.dart @@ -17,8 +17,8 @@ class LoginModel { Map toJson() { final Map data = new Map(); - data['usuario'] = this.usuario; - data['senha'] = this.senha; + data['usuario'] = usuario; + data['senha'] = senha; return data; } diff --git a/lib/Model/Projeto/ProjetoModel.dart b/lib/Model/Projeto/ProjetoModel.dart new file mode 100644 index 0000000..7876edd --- /dev/null +++ b/lib/Model/Projeto/ProjetoModel.dart @@ -0,0 +1,40 @@ +import 'package:organizei/Model/API/ResponseAPIModel.dart'; + +class ProjetoModel { + int? id; + String? nome; + String? dataInicial; + String? observacao; + String? dataFinal; + String? cor; + ResponseAPIModel? responseAPIModel; + + ProjetoModel( + {this.id, + this.nome, + this.dataInicial, + this.observacao, + this.dataFinal, + this.cor}); + + ProjetoModel.fromJson(Map json) { + id = int.parse(json['id']); + nome = json['nome']; + dataInicial = json['dataInicial']; + observacao = json['observacao']; + dataFinal = json['dataFinal']; + cor = json['cor']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = id; + data['nome'] = nome; + data['dataInicial'] = dataInicial; + data['observacao'] = observacao; + data['dataFinal'] = dataFinal; + data['cor'] = cor; + + return data; + } +} diff --git a/lib/Model/Tarefa/TarefaModel.dart b/lib/Model/Tarefa/TarefaModel.dart index c4a4d48..511a6eb 100644 --- a/lib/Model/Tarefa/TarefaModel.dart +++ b/lib/Model/Tarefa/TarefaModel.dart @@ -28,12 +28,12 @@ class TarefaModel { Map toJson() { final Map data = new Map(); - data['id'] = this.id; - data['nome'] = this.nome; - data['data'] = this.data; - data['observacao'] = this.observacao; - data['prioridade'] = this.prioridade; - data['cor'] = this.cor; + data['id'] = id; + data['nome'] = nome; + data['data'] = data; + data['observacao'] = observacao; + data['prioridade'] = prioridade; + data['cor'] = cor; return data; } diff --git a/lib/Repository/HabitoRepository.dart b/lib/Repository/HabitoRepository.dart index 6d455db..33b17b6 100644 --- a/lib/Repository/HabitoRepository.dart +++ b/lib/Repository/HabitoRepository.dart @@ -65,9 +65,9 @@ class HabitoRepository { } Future> getHabitos() async { - Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/habitos'); + Uri url = Uri.parse(ApiModel.ApiUrl + '/habitos'); - var _url = Uri.parse(_uriSearchProduto.toString()); + var _url = Uri.parse(url.toString()); final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); diff --git a/lib/Repository/LembreteRepository.dart b/lib/Repository/LembreteRepository.dart index b1540f0..8ac27c6 100644 --- a/lib/Repository/LembreteRepository.dart +++ b/lib/Repository/LembreteRepository.dart @@ -46,9 +46,9 @@ class LembreteRepository { } Future> getLembretes() async { - Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes'); + Uri url = Uri.parse(ApiModel.ApiUrl + '/lembretes'); - var _url = Uri.parse(_uriSearchProduto.toString()); + var _url = Uri.parse(url.toString()); final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); @@ -77,9 +77,9 @@ class LembreteRepository { } Future> get() async { - Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes'); + Uri url = Uri.parse(ApiModel.ApiUrl + '/lembretes'); - var _url = Uri.parse(_uriSearchProduto.toString()); + var _url = Uri.parse(url.toString()); final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); diff --git a/lib/Repository/ListaRepository.dart b/lib/Repository/ListaRepository.dart index 0b382fc..e5d9b13 100644 --- a/lib/Repository/ListaRepository.dart +++ b/lib/Repository/ListaRepository.dart @@ -38,9 +38,9 @@ class ListaRepository { } Future> getListas() async { - Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/listas'); + Uri url = Uri.parse(ApiModel.ApiUrl + '/listas'); - var _url = Uri.parse(_uriSearchProduto.toString()); + var _url = Uri.parse(url.toString()); final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); diff --git a/lib/Repository/ProjetoRepository.dart b/lib/Repository/ProjetoRepository.dart new file mode 100644 index 0000000..0fe60c0 --- /dev/null +++ b/lib/Repository/ProjetoRepository.dart @@ -0,0 +1,88 @@ +import 'dart:convert'; + +import 'package:organizei/Model/API/APIModel.dart'; + +import 'package:http/http.dart' as http; +import 'package:organizei/Model/API/ResponseAPIModel.dart'; +import 'package:organizei/Model/Projeto/ProjetoModel.dart'; + +class ProjetoRepository { + Future addProjeto(ProjetoModel model) async { + var json = { + "nome": model.nome, + "dataInicial": model.dataInicial, + "observacao": model.observacao, + "dataFinal": model.dataFinal, + "cor": model.cor, + }; + + print('olha to here'); + + final response = await http.post(Uri.parse(ApiModel.ApiUrl + '/projetos'), + headers: ApiModel.headers, body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future updateProjeto(ProjetoModel model) async { + var json = { + "nome": model.nome, + "dataInicial": model.dataInicial, + "observacao": model.observacao, + "dataFinal": model.dataFinal, + "cor": model.cor, + }; + + final response = await http.put( + Uri.parse(ApiModel.ApiUrl + '/projetos/' + model.id.toString()), + headers: ApiModel.headers, + body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future concluirProjeto( + ProjetoModel model, bool concluido) async { + var json = { + "concluido": concluido, + }; + + final response = await http.put( + Uri.parse( + ApiModel.ApiUrl + '/projetos/' + model.id.toString() + '/concluir'), + headers: ApiModel.headers, + body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future excluirProjeto(ProjetoModel model) async { + final response = await http.delete( + Uri.parse(ApiModel.ApiUrl + '/projetos/' + model.id.toString()), + headers: ApiModel.headers); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future> getProjetos() async { + Uri url = Uri.parse(ApiModel.ApiUrl + '/projetos'); + + var _url = Uri.parse(url.toString()); + final response = await http.get(_url, headers: ApiModel.headers); + + Map jsonMap = jsonDecode(response.body); + + return jsonMap; + } + + Future> get() async { + Uri url = Uri.parse(ApiModel.ApiUrl + '/projetos'); + + var _url = Uri.parse(url.toString()); + final response = await http.get(_url, headers: ApiModel.headers); + + Map jsonMap = jsonDecode(response.body); + + return jsonMap; + } +} diff --git a/lib/Repository/TarefaRepository.dart b/lib/Repository/TarefaRepository.dart index 04493b4..06521fe 100644 --- a/lib/Repository/TarefaRepository.dart +++ b/lib/Repository/TarefaRepository.dart @@ -63,9 +63,9 @@ class TarefaRepository { } Future> getTarefas() async { - Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/tarefas'); + Uri url = Uri.parse(ApiModel.ApiUrl + '/tarefas'); - var _url = Uri.parse(_uriSearchProduto.toString()); + var _url = Uri.parse(url.toString()); final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); @@ -77,9 +77,9 @@ class TarefaRepository { } Future> get() async { - Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/tarefas'); + Uri url = Uri.parse(ApiModel.ApiUrl + '/tarefas'); - var _url = Uri.parse(_uriSearchProduto.toString()); + var _url = Uri.parse(url.toString()); final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); diff --git a/lib/components/dialogs/projetos/projetoCadastroDialog.dart b/lib/components/dialogs/projetos/projetoCadastroDialog.dart new file mode 100644 index 0000000..799b6d4 --- /dev/null +++ b/lib/components/dialogs/projetos/projetoCadastroDialog.dart @@ -0,0 +1,111 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Model/Projeto/ProjetoModel.dart'; +import 'package:organizei/Repository/ProjetoRepository.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/ProjetoController.dart'; + +Future criarProjeto(BuildContext context, + {ProjetoModel? projeto = null, Function? fecharDialog = null}) { + late ProjetoController projetoController; + + projetoController = ProjetoController(ProjetoRepository(), context); + + if (projeto != null) { + projetoController.controllerNome.text = projeto.nome ?? ''; + projetoController.controllerDataIncial.text = projeto.dataInicial ?? ''; + projetoController.controllerDataFinal.text = projeto.dataFinal ?? ''; + projetoController.controllerObservacao.text = projeto.observacao ?? ''; + projetoController.projetoCor(projeto.cor); + projetoController.projetoId(projeto.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: projetoController.formKey, + child: Padding( + padding: const EdgeInsets.only(top: 24.0), + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: MediaQuery.of(context).size.height, + ), + child: DialogPersonalizado( + nome: 'Projeto', + child: [ + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: projetoController.projetoNome, + textController: projetoController.controllerNome, + label: 'nome', + ), + ), + SelectData( + label: 'data inicial', + tipo: 'data', + controller: projetoController.controllerDataIncial, + onSaved: projetoController.projetoDataInical, + ), + SelectData( + label: 'data final', + tipo: 'data', + controller: projetoController.controllerDataFinal, + onSaved: projetoController.projetoDataFinal, + ), + Padding( + padding: const EdgeInsets.only(bottom: 16), + child: input( + onSaved: projetoController.projetoObservacao, + textController: + projetoController.controllerObservacao, + label: 'observação', + ), + ), + SelectCor( + cor: projetoController.projetoCor, + corAtual: projeto?.cor ?? ''), + Botao( + texto: 'Salvar', + cor: const Color(0xFF6385C3), + clicar: () async { + bool succes = + await projetoController.saveProjeto(); + + if (succes == true) { + var nav = Navigator.of(context); + nav.pop(); + + if (projeto?.id != null) { + //nav.pop(); + nav.pop(); + } + fecharDialog!(); + } + }, + ), + ], + ), + ), + ), + ), + ), + ), + ); + }); + }); +} diff --git a/lib/components/dialogs/projetos/projetoDialog.dart b/lib/components/dialogs/projetos/projetoDialog.dart new file mode 100644 index 0000000..fa5defd --- /dev/null +++ b/lib/components/dialogs/projetos/projetoDialog.dart @@ -0,0 +1,119 @@ +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 visualizarProjeto(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: Padding( + padding: const EdgeInsets.only(top: 24.0), + child: ConstrainedBox( + constraints: BoxConstraints( + minHeight: MediaQuery.of(context).size.height, + ), + 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 9b8d2f7..8c6158e 100644 --- a/lib/components/navigation/menu.dart +++ b/lib/components/navigation/menu.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:organizei/components/dialog_personalizado.dart'; import 'package:organizei/components/dialogs/lembretes/lembreteCadastroDialog.dart'; import 'package:organizei/components/dialogs/listas/listaCadastroDialog.dart'; +import 'package:organizei/components/dialogs/projetos/projetoCadastroDialog.dart'; import 'package:organizei/components/dialogs/tarefas/tarefaCadastroDialog.dart'; import 'package:organizei/components/dialogs/habitos/habitoCadastroDialog.dart'; @@ -51,7 +52,7 @@ class _MenuState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: const [ Text( 'criar lista', style: TextStyle(fontSize: 24.0), @@ -60,7 +61,7 @@ class _MenuState extends State { ), ), ), - Divider( + const Divider( thickness: 3, color: Colors.black, ), @@ -73,7 +74,7 @@ class _MenuState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: const [ Text( 'criar tarefa', style: TextStyle(fontSize: 24.0), @@ -82,7 +83,7 @@ class _MenuState extends State { ), ), ), - Divider( + const Divider( thickness: 3, color: Colors.black, ), @@ -95,7 +96,7 @@ class _MenuState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: const [ Text( 'criar hábito', style: TextStyle(fontSize: 24.0), @@ -104,21 +105,29 @@ class _MenuState extends State { ), ), ), - Divider( + const Divider( thickness: 3, color: Colors.black, ), - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - 'criar projeto', - style: TextStyle(fontSize: 24.0), + GestureDetector( + onTap: () { + criarProjeto(context, fecharDialog: widget.fecharDialog); + widget.fecharMenu!(); + }, + child: AbsorbPointer( + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Text( + 'criar projeto', + style: TextStyle(fontSize: 24.0), + ), + ], ), - ], + ), ), - Divider( + const Divider( thickness: 3, color: Colors.black, ), @@ -131,8 +140,8 @@ class _MenuState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( + children: const [ + Text( 'criar lembrete', style: TextStyle(fontSize: 24.0), ), diff --git a/lib/home_page.dart b/lib/home_page.dart index 003ee5b..cd4b2ac 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -175,8 +175,11 @@ class _HomePageState extends State { if (snapshot.data.length == 0) { return const Center( - child: Text( - "Você não tem nada pra fazer hoje!"), + child: Padding( + padding: EdgeInsets.only(top: 32.0), + child: + Text("Você não tem nada pra fazer!"), + ), ); } diff --git a/lib/listas_page.dart b/lib/listas_page.dart index 49ed47b..77ba541 100644 --- a/lib/listas_page.dart +++ b/lib/listas_page.dart @@ -74,8 +74,10 @@ class _HomePageState extends State { if (snapshot.data['listas'].length == 0) { return const Center( - child: - Text("Você não tem nada pra fazer hoje!"), + child: Padding( + padding: EdgeInsets.only(top: 32.0), + child: Text("Você não tem listas!"), + ), ); }