From 982f7a34c6d3e4fac3c50845b28060aa812fee56 Mon Sep 17 00:00:00 2001 From: Willian <47341070+wjrcode@users.noreply.github.com> Date: Fri, 30 Sep 2022 15:19:32 -0300 Subject: [PATCH] mexi em coisas bei --- lib/Controller/SplashController.dart | 2 +- lib/Controller/TarefaController.dart | 40 +++ lib/Repository/TarefaRepository.dart | 17 +- lib/components/dialog_personalizado.dart | 4 +- .../dialogs/tarefaCadastroDialog.dart | 9 +- lib/components/dialogs/tarefaDialog.dart | 66 +++- lib/components/input.dart | 19 +- lib/components/selectData.dart | 328 +++++++++++++----- lib/home_page.dart | 22 +- lib/start_page.dart | 2 +- 10 files changed, 378 insertions(+), 131 deletions(-) diff --git a/lib/Controller/SplashController.dart b/lib/Controller/SplashController.dart index 60ea4c7..ed5579a 100644 --- a/lib/Controller/SplashController.dart +++ b/lib/Controller/SplashController.dart @@ -16,7 +16,7 @@ class SplashController extends Base { String? apelido = prefs.getString('UsuarioApelido'); if (login != null) { - return HomePage(apelido: apelido); + return HomePage(); } else return StartPage(); } diff --git a/lib/Controller/TarefaController.dart b/lib/Controller/TarefaController.dart index 540a698..fa26d8b 100644 --- a/lib/Controller/TarefaController.dart +++ b/lib/Controller/TarefaController.dart @@ -109,4 +109,44 @@ class TarefaController extends Base { Future?> getTarefas() async { return await repository.getTarefas(); } + + Future concluirTarefa(bool concluido) async { + try { + return await repository + .concluirTarefa(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; + } + } } diff --git a/lib/Repository/TarefaRepository.dart b/lib/Repository/TarefaRepository.dart index 3fec0f0..29c4a4c 100644 --- a/lib/Repository/TarefaRepository.dart +++ b/lib/Repository/TarefaRepository.dart @@ -31,8 +31,6 @@ class TarefaRepository { "cor": model.cor, }; - print(ApiModel.ApiUrl + '/tarefas/' + model.id.toString()); - final response = await http.put( Uri.parse(ApiModel.ApiUrl + '/tarefas/' + model.id.toString()), headers: ApiModel.headers, @@ -41,6 +39,21 @@ class TarefaRepository { return ResponseAPIModel.fromJson(jsonDecode(response.body)); } + Future concluirTarefa( + TarefaModel model, bool concluido) async { + var json = { + "concluido": concluido, + }; + + final response = await http.put( + Uri.parse( + ApiModel.ApiUrl + '/tarefas/' + model.id.toString() + '/concluir'), + headers: ApiModel.headers, + body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + Future> getTarefas() async { Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/tarefas'); diff --git a/lib/components/dialog_personalizado.dart b/lib/components/dialog_personalizado.dart index 0417379..3596536 100644 --- a/lib/components/dialog_personalizado.dart +++ b/lib/components/dialog_personalizado.dart @@ -7,10 +7,12 @@ class DialogPersonalizado extends StatefulWidget { Key? key, required this.child, required this.nome, + this.cor = '', }) : super(key: key); final List child; final String nome; + final String cor; @override State createState() => _DialogPersonalizadoState(); @@ -81,7 +83,7 @@ class _DialogPersonalizadoState extends State TextoContornado( texto: widget.nome, tamanho: 32, - cor: const Color(0xFF6385C3), + cor: Color(int.tryParse(widget.cor) ?? 0xFF6385C3), ), ], ), diff --git a/lib/components/dialogs/tarefaCadastroDialog.dart b/lib/components/dialogs/tarefaCadastroDialog.dart index a3b22a6..b7cae4a 100644 --- a/lib/components/dialogs/tarefaCadastroDialog.dart +++ b/lib/components/dialogs/tarefaCadastroDialog.dart @@ -7,6 +7,7 @@ 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, @@ -78,7 +79,13 @@ Future criarTarefa(BuildContext context, bool succes = await tarefaController.saveTarefa(); if (succes == true) { - Navigator.pop(context); + var nav = Navigator.of(context); + nav.pop(); + + if (tarefa?.id != null) { + //nav.pop(); + nav.pop(); + } fecharDialog!(); } }, diff --git a/lib/components/dialogs/tarefaDialog.dart b/lib/components/dialogs/tarefaDialog.dart index 8aade9e..9748290 100644 --- a/lib/components/dialogs/tarefaDialog.dart +++ b/lib/components/dialogs/tarefaDialog.dart @@ -4,19 +4,14 @@ import 'package:organizei/Repository/TarefaRepository.dart'; import 'package:organizei/components/botao.dart'; import 'package:organizei/components/dialog_personalizado.dart'; import 'package:organizei/components/dialogs/tarefaCadastroDialog.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/TarefaController.dart'; Future visualizarTarefa(BuildContext context, {required TarefaModel tarefa, Function? fecharDialog = null}) { late TarefaController tarefaController; - //setState(() { tarefaController = TarefaController(TarefaRepository(), context); - // }); + tarefaController.tarefaId(tarefa.id); return showDialog( barrierDismissible: false, @@ -37,25 +32,60 @@ Future visualizarTarefa(BuildContext context, margin: const EdgeInsets.only(top: 24), child: DialogPersonalizado( nome: tarefa.nome ?? '', + cor: tarefa.cor ?? '', child: [ - Botao( - texto: 'Concluir', - cor: const Color(0xFF74C198), - clicar: () async { - // bool succes = await tarefaController.saveTarefa(); + 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!(); - // } - }, + if (succes == true) { + Navigator.pop(context); + fecharDialog!(); + } + }, + ), ), Botao( texto: 'Editar', cor: const Color(0xFF6385C3), clicar: () async { - Navigator.pop(context); - criarTarefa(context, tarefa: tarefa); + // Navigator.pop(context); + criarTarefa(context, + tarefa: tarefa, fecharDialog: fecharDialog); // bool succes = await tarefaController.saveTarefa(); diff --git a/lib/components/input.dart b/lib/components/input.dart index 625fcee..983d3f7 100644 --- a/lib/components/input.dart +++ b/lib/components/input.dart @@ -1,13 +1,13 @@ import 'package:flutter/material.dart'; -Widget input( - {dynamic onSaved, - TextEditingController? textController, - String? label, - bool senha = false, - bool readOnly = false, - String? placeholder = '', - Function? customFunction}) { +Widget input({ + dynamic onSaved, + TextEditingController? textController, + String? label, + bool senha = false, + bool readOnly = false, + String? placeholder = '', +}) { return Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, @@ -24,9 +24,6 @@ Widget input( color: Colors.white.withOpacity(0), child: TextFormField( obscureText: senha, - onTap: () { - return customFunction!(); - }, readOnly: readOnly, onSaved: onSaved, controller: textController, diff --git a/lib/components/selectData.dart b/lib/components/selectData.dart index 061bd57..9821278 100644 --- a/lib/components/selectData.dart +++ b/lib/components/selectData.dart @@ -27,109 +27,253 @@ class _SelectDataState extends State { @override Widget build(BuildContext context) { return Padding( - padding: const EdgeInsets.only(bottom: 16), - child: input( - onSaved: widget.onSaved, - textController: widget.controller, - label: 'data e hora', - placeholder: 'Selecione a data e hora', - readOnly: true, - customFunction: () async { - DateTime date = new DateTime.now(); - - DateTime? newDate = await showDatePicker( - context: context, - initialDate: date, - firstDate: DateTime(2020), - lastDate: DateTime(2100), - builder: (BuildContext context, child) { - return Theme( - data: Theme.of(context).copyWith( - colorScheme: const ColorScheme.light( - primary: Color(0xFF6385C3), - ), - dialogTheme: DialogTheme( - backgroundColor: const Color(0xFFE9E9E9), - elevation: 1, - shape: RoundedRectangleBorder( - side: const BorderSide(width: 3, color: Colors.black), - borderRadius: BorderRadius.circular(16.0), + padding: const EdgeInsets.only(bottom: 16), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'data e hora', + style: TextStyle( + color: Colors.black, + fontSize: 16, + fontWeight: FontWeight.w400, + ), + ), + Material( + color: Colors.white.withOpacity(0), + child: TextFormField( + onTap: () async { + DateTime date = new DateTime.now(); + + DateTime? newDate = await showDatePicker( + context: context, + initialDate: date, + firstDate: DateTime(2020), + lastDate: DateTime(2100), + builder: (BuildContext context, child) { + return Theme( + data: Theme.of(context).copyWith( + colorScheme: const ColorScheme.light( + primary: Color(0xFF6385C3), + ), + dialogTheme: DialogTheme( + backgroundColor: const Color(0xFFE9E9E9), + elevation: 1, + shape: RoundedRectangleBorder( + side: const BorderSide( + width: 3, color: Colors.black), + borderRadius: BorderRadius.circular(16.0), + ), + ), + ), + child: child!, + ); + }, + ); + + if (newDate == null) return; + + final time = await showTimePicker( + context: context, + initialTime: + TimeOfDay(hour: date.hour, minute: date.minute), + builder: (BuildContext context, child) { + return Theme( + data: ThemeData.light().copyWith( + timePickerTheme: TimePickerThemeData( + shape: RoundedRectangleBorder( + side: const BorderSide( + width: 3, color: Colors.black), + borderRadius: BorderRadius.circular(16.0), + ), + backgroundColor: const Color(0xFFE9E9E9), + hourMinuteColor: MaterialStateColor.resolveWith( + (states) => + states.contains(MaterialState.selected) + ? const Color(0xFFE9E9E9) + : const Color(0xFFE9E9E9)), + dialHandColor: Color(0xFFE9E9E9), + dialTextColor: MaterialStateColor.resolveWith( + (states) => + states.contains(MaterialState.selected) + ? Colors.black + : Colors.black), + hourMinuteTextColor: + MaterialStateColor.resolveWith((states) => + states.contains(MaterialState.selected) + ? const Color(0xFF6385C3) + : Colors.black), + dialBackgroundColor: const Color(0xFF6385C3), + ), + textButtonTheme: TextButtonThemeData( + style: ButtonStyle( + foregroundColor: + MaterialStateColor.resolveWith( + (states) => const Color(0xFF6385C3)), + overlayColor: MaterialStateColor.resolveWith( + (states) => const Color(0xFF6385C3), + ), + ), + ), + ), + child: child!, + ); + }); + + if (time == null) return; + + final newDateTime = DateTime( + newDate.year, + newDate.month, + newDate.day, + time.hour, + time.minute, + ); + + setState(() { + date = newDate; + }); + + widget.onSaved(newDateTime.toString()); + + intl.Intl.defaultLocale = 'pt_BR'; + initializeDateFormatting('pt_BR'); + + intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); + + widget.controller!.text = + intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); + }, + readOnly: true, + onSaved: widget.onSaved, + controller: widget.controller, + decoration: InputDecoration( + hintText: 'Selecione a data e hora', + fillColor: Colors.white, + filled: true, + enabledBorder: OutlineInputBorder( + borderSide: const BorderSide( + color: Colors.black, + width: 3.0, ), + borderRadius: BorderRadius.circular(16.0), ), - ), - child: child!, - ); - }, - ); - - if (newDate == null) return; - - final time = await showTimePicker( - context: context, - initialTime: TimeOfDay(hour: date.hour, minute: date.minute), - builder: (BuildContext context, child) { - return Theme( - data: ThemeData.light().copyWith( - timePickerTheme: TimePickerThemeData( - shape: RoundedRectangleBorder( - side: const BorderSide(width: 3, color: Colors.black), - borderRadius: BorderRadius.circular(16.0), - ), - backgroundColor: const Color(0xFFE9E9E9), - hourMinuteColor: MaterialStateColor.resolveWith( - (states) => states.contains(MaterialState.selected) - ? const Color(0xFFE9E9E9) - : const Color(0xFFE9E9E9)), - dialHandColor: Color(0xFFE9E9E9), - dialTextColor: MaterialStateColor.resolveWith( - (states) => states.contains(MaterialState.selected) - ? Colors.black - : Colors.black), - hourMinuteTextColor: MaterialStateColor.resolveWith( - (states) => states.contains(MaterialState.selected) - ? const Color(0xFF6385C3) - : Colors.black), - dialBackgroundColor: const Color(0xFF6385C3), - ), - textButtonTheme: TextButtonThemeData( - style: ButtonStyle( - foregroundColor: MaterialStateColor.resolveWith( - (states) => const Color(0xFF6385C3)), - overlayColor: MaterialStateColor.resolveWith( - (states) => const Color(0xFF6385C3), - ), - ), + focusedBorder: OutlineInputBorder( + borderSide: const BorderSide( + color: Colors.black, + width: 3.0, ), + borderRadius: BorderRadius.circular(16.0), ), - child: child!, - ); - }); - if (time == null) return; + //labelText: 'Password', + ), + ), + ) + ]) + // child: input( + // onSaved: widget.onSaved, + // textController: widget.controller, + // label: 'data e hora', + // placeholder: 'Selecione a data e hora', + // readOnly: true, + // customFunction: () async { + // DateTime date = new DateTime.now(); + + // DateTime? newDate = await showDatePicker( + // context: context, + // initialDate: date, + // firstDate: DateTime(2020), + // lastDate: DateTime(2100), + // builder: (BuildContext context, child) { + // return Theme( + // data: Theme.of(context).copyWith( + // colorScheme: const ColorScheme.light( + // primary: Color(0xFF6385C3), + // ), + // dialogTheme: DialogTheme( + // backgroundColor: const Color(0xFFE9E9E9), + // elevation: 1, + // shape: RoundedRectangleBorder( + // side: const BorderSide(width: 3, color: Colors.black), + // borderRadius: BorderRadius.circular(16.0), + // ), + // ), + // ), + // child: child!, + // ); + // }, + // ); - final newDateTime = DateTime( - newDate.year, - newDate.month, - newDate.day, - time.hour, - time.minute, - ); + // if (newDate == null) return; - setState(() { - date = newDate; - }); + // final time = await showTimePicker( + // context: context, + // initialTime: TimeOfDay(hour: date.hour, minute: date.minute), + // builder: (BuildContext context, child) { + // return Theme( + // data: ThemeData.light().copyWith( + // timePickerTheme: TimePickerThemeData( + // shape: RoundedRectangleBorder( + // side: const BorderSide(width: 3, color: Colors.black), + // borderRadius: BorderRadius.circular(16.0), + // ), + // backgroundColor: const Color(0xFFE9E9E9), + // hourMinuteColor: MaterialStateColor.resolveWith( + // (states) => states.contains(MaterialState.selected) + // ? const Color(0xFFE9E9E9) + // : const Color(0xFFE9E9E9)), + // dialHandColor: Color(0xFFE9E9E9), + // dialTextColor: MaterialStateColor.resolveWith( + // (states) => states.contains(MaterialState.selected) + // ? Colors.black + // : Colors.black), + // hourMinuteTextColor: MaterialStateColor.resolveWith( + // (states) => states.contains(MaterialState.selected) + // ? const Color(0xFF6385C3) + // : Colors.black), + // dialBackgroundColor: const Color(0xFF6385C3), + // ), + // textButtonTheme: TextButtonThemeData( + // style: ButtonStyle( + // foregroundColor: MaterialStateColor.resolveWith( + // (states) => const Color(0xFF6385C3)), + // overlayColor: MaterialStateColor.resolveWith( + // (states) => const Color(0xFF6385C3), + // ), + // ), + // ), + // ), + // child: child!, + // ); + // }); - widget.onSaved(newDateTime.toString()); + // if (time == null) return; - intl.Intl.defaultLocale = 'pt_BR'; - initializeDateFormatting('pt_BR'); + // final newDateTime = DateTime( + // newDate.year, + // newDate.month, + // newDate.day, + // time.hour, + // time.minute, + // ); - intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); + // setState(() { + // date = newDate; + // }); - widget.controller!.text = - intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); - }), - ); + // widget.onSaved(newDateTime.toString()); + + // intl.Intl.defaultLocale = 'pt_BR'; + // initializeDateFormatting('pt_BR'); + + // intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); + + // widget.controller!.text = + // intl.DateFormat('dd/MM/yyyy HH:mm').format(newDateTime); + // }), + ); } } diff --git a/lib/home_page.dart b/lib/home_page.dart index f35e09f..52f7d5e 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -5,7 +5,6 @@ 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/tarefaCadastroDialog.dart'; import 'package:organizei/components/dialogs/tarefaDialog.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -35,14 +34,29 @@ String getDia() { } class HomePage extends StatefulWidget { - const HomePage({Key? key, required this.apelido}) : super(key: key); - final String? apelido; + const HomePage({Key? key}) : super(key: key); @override State createState() => _HomePageState(); } class _HomePageState extends State { + late String? apelido = ''; + + @override + initState() { + getApelido(); + super.initState(); + } + + getApelido() async { + SharedPreferences prefs = await SharedPreferences.getInstance(); + + setState(() { + apelido = prefs.getString('UsuarioApelido'); + }); + } + @override Widget build(BuildContext context) { late TarefaController tarefaController; @@ -82,7 +96,7 @@ class _HomePageState extends State { ), ), TextoContornado( - texto: widget.apelido!, + texto: apelido!, tamanho: 32, cor: const Color(0xFFF7BC36), ) diff --git a/lib/start_page.dart b/lib/start_page.dart index 7a66e13..4d9f1fd 100644 --- a/lib/start_page.dart +++ b/lib/start_page.dart @@ -137,7 +137,7 @@ class _StartPageState extends State { Navigator.of(context).push( MaterialPageRoute( builder: (BuildContext context) => - HomePage(apelido: apelido), + HomePage(), ), ); }