diff --git a/lib/Controller/HabitoController.dart b/lib/Controller/HabitoController.dart new file mode 100644 index 0000000..ffa4810 --- /dev/null +++ b/lib/Controller/HabitoController.dart @@ -0,0 +1,189 @@ +import 'dart:ffi'; + +import 'package:flutter/material.dart'; +import 'package:http/http.dart'; +import 'package:organizei/Model/Habito/HabitoModel.dart'; +import 'package:organizei/Controller/Base/Base.dart'; +import 'package:organizei/Repository/HabitoRepository.dart'; +import 'package:organizei/services/persistencia/login.configuracoes.dart'; + +class HabitoController extends Base { + HabitoController(this.repository, this.context); + + final BuildContext context; + final HabitoRepository repository; + final formKey = GlobalKey(); + var model = HabitoModel(); + //var loginConfiguracoes = LoginConfiguracoes(); + + habitoId(int? value) => model.id = value; + habitoNome(String? value) => model.nome = value.toString(); + habitoDataehora(String? value) => model.data = value.toString(); + habitoDias(List? value) => model.dias = value!.cast(); + habitoCor(String? value) => model.cor = value.toString(); + + var controllerNome = TextEditingController(); + var controllerDias = TextEditingController(); + var controllerPrioridade = TextEditingController(); + var controllerCor = TextEditingController(); + var controllerDataehora = TextEditingController(); + + Future saveHabito() async { + if (!formKey.currentState!.validate()) { + return false; + } + + formKey.currentState!.save(); + + try { + if (model.id == null) { + return await repository.addHabito(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.updateHabito(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?> getHabitos() async { + return await repository.getHabitos(); + } + + Future concluirHabito(bool concluido) async { + try { + return await repository + .concluirHabito(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 excluirHabito() async { + try { + return await repository.excluirHabito(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/Controller/TarefaController.dart b/lib/Controller/TarefaController.dart index cf686b7..721f054 100644 --- a/lib/Controller/TarefaController.dart +++ b/lib/Controller/TarefaController.dart @@ -110,6 +110,10 @@ class TarefaController extends Base { return await repository.getTarefas(); } + Future> get() async { + return await repository.get(); + } + Future concluirTarefa(bool concluido) async { try { return await repository diff --git a/lib/Model/Generica.dart b/lib/Model/Generica.dart new file mode 100644 index 0000000..293b3d5 --- /dev/null +++ b/lib/Model/Generica.dart @@ -0,0 +1,19 @@ +import 'package:organizei/Model/API/ResponseAPIModel.dart'; + +class GenericaModel { + String? tipo; + + ResponseAPIModel? responseAPIModel; + + GenericaModel({this.tipo}); + + GenericaModel.fromJson(Map json) { + tipo = json['tipo']; + } + + Map toJson() { + final Map data = new Map(); + data['tipo'] = this.tipo; + return data; + } +} diff --git a/lib/Model/Habito/HabitoModel.dart b/lib/Model/Habito/HabitoModel.dart new file mode 100644 index 0000000..bf120a5 --- /dev/null +++ b/lib/Model/Habito/HabitoModel.dart @@ -0,0 +1,32 @@ +import 'package:organizei/Model/API/ResponseAPIModel.dart'; +import 'package:organizei/Model/Generica.dart'; + +class HabitoModel extends GenericaModel { + int? id; + String? nome; + String? data; + List? dias; + String? cor; + ResponseAPIModel? responseAPIModel; + + HabitoModel({this.id, this.nome, this.data, this.dias, this.cor}); + + HabitoModel.fromJson(Map json) { + id = int.parse(json['id']); + nome = json['nome']; + data = json['hora']; + dias = json['dias']; + cor = json['cor']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['nome'] = this.nome; + data['hora'] = this.data; + data['dias'] = this.dias; + data['cor'] = this.cor; + + return data; + } +} diff --git a/lib/Repository/HabitoRepository.dart b/lib/Repository/HabitoRepository.dart new file mode 100644 index 0000000..474f6f0 --- /dev/null +++ b/lib/Repository/HabitoRepository.dart @@ -0,0 +1,76 @@ +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/Habito/HabitoModel.dart'; + +class HabitoRepository { + Future addHabito(HabitoModel model) async { + var json = { + "nome": model.nome, + "hora": model.data, + "dias": model.dias, + "cor": model.cor, + }; + + final response = await http.post(Uri.parse(ApiModel.ApiUrl + '/habitos'), + headers: ApiModel.headers, body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future updateHabito(HabitoModel model) async { + var json = { + "nome": model.nome, + "hora": model.data, + "dias": model.dias, + "cor": model.cor, + }; + + final response = await http.put( + Uri.parse(ApiModel.ApiUrl + '/habitos/' + model.id.toString()), + headers: ApiModel.headers, + body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future concluirHabito( + HabitoModel model, bool concluido) async { + var json = { + "concluido": concluido, + }; + + final response = await http.put( + Uri.parse( + ApiModel.ApiUrl + '/habitos/' + model.id.toString() + '/concluir'), + headers: ApiModel.headers, + body: jsonEncode(json)); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future excluirHabito(HabitoModel model) async { + final response = await http.delete( + Uri.parse(ApiModel.ApiUrl + '/habitos/' + model.id.toString()), + headers: ApiModel.headers); + + return ResponseAPIModel.fromJson(jsonDecode(response.body)); + } + + Future> getHabitos() async { + Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/habitos'); + + var _url = Uri.parse(_uriSearchProduto.toString()); + final response = await http.get(_url, headers: ApiModel.headers); + + Map jsonMap = jsonDecode(response.body); + List listaProdutos = (jsonMap['habitos'] as List) + .map((item) => HabitoModel.fromJson(item)) + .toList(); + + return listaProdutos; + } +} diff --git a/lib/Repository/TarefaRepository.dart b/lib/Repository/TarefaRepository.dart index 2414a39..04493b4 100644 --- a/lib/Repository/TarefaRepository.dart +++ b/lib/Repository/TarefaRepository.dart @@ -69,10 +69,21 @@ class TarefaRepository { final response = await http.get(_url, headers: ApiModel.headers); Map jsonMap = jsonDecode(response.body); - List listaProdutos = (jsonMap['tarefas'] as List) + List listaTarefas = (jsonMap['tarefas'] as List) .map((item) => TarefaModel.fromJson(item)) .toList(); - return listaProdutos; + return listaTarefas; + } + + Future> get() async { + Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/tarefas'); + + var _url = Uri.parse(_uriSearchProduto.toString()); + final response = await http.get(_url, headers: ApiModel.headers); + + Map jsonMap = jsonDecode(response.body); + + return jsonMap; } } diff --git a/lib/components/dialogs/tarefaCadastroHabito.dart b/lib/components/dialogs/habitos/habitoCadastroDialog.dart similarity index 50% rename from lib/components/dialogs/tarefaCadastroHabito.dart rename to lib/components/dialogs/habitos/habitoCadastroDialog.dart index e007620..8e805cb 100644 --- a/lib/components/dialogs/tarefaCadastroHabito.dart +++ b/lib/components/dialogs/habitos/habitoCadastroDialog.dart @@ -1,29 +1,26 @@ import 'package:flutter/material.dart'; -import 'package:organizei/Model/Tarefa/TarefaModel.dart'; -import 'package:organizei/Repository/TarefaRepository.dart'; +import 'package:organizei/Model/Habito/HabitoModel.dart'; +import 'package:organizei/Repository/HabitoRepository.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'; +import '../../../Controller/HabitoController.dart'; Future criarHabito(BuildContext context, - {TarefaModel? tarefa = null, Function? fecharDialog = null}) { - late TarefaController tarefaController; + {HabitoModel? habito = null, Function? fecharDialog = null}) { + late HabitoController habitoController; - tarefaController = TarefaController(TarefaRepository(), context); + habitoController = HabitoController(HabitoRepository(), 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); + if (habito != null) { + habitoController.controllerNome.text = habito.nome ?? ''; + habitoController.controllerDataehora.text = habito.data ?? ''; + habitoController.controllerDias.text = habito.dias.toString(); + habitoController.habitoCor(habito.cor); + habitoController.habitoId(habito.id); } return showDialog( @@ -39,53 +36,42 @@ Future criarHabito(BuildContext context, child: Material( type: MaterialType.transparency, child: Form( - key: tarefaController.formKey, + key: habitoController.formKey, child: Container( margin: const EdgeInsets.only(top: 24), + height: MediaQuery.of(context).size.height, child: DialogPersonalizado( nome: 'Hábito', child: [ Padding( padding: const EdgeInsets.only(bottom: 16), child: input( - onSaved: tarefaController.tarefaNome, - textController: tarefaController.controllerNome, + onSaved: habitoController.habitoNome, + textController: habitoController.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), + controller: habitoController.controllerDataehora, + onSaved: habitoController.habitoDataehora), + SelectDia( + dia: habitoController.habitoDias, + diaAtual: habito?.dias ?? + ['0', '0', '0', '0', '0', '0', '0']), SelectCor( - cor: tarefaController.tarefaCor, - corAtual: tarefa?.cor ?? ''), + cor: habitoController.habitoCor, + corAtual: habito?.cor ?? ''), Botao( texto: 'Salvar', cor: const Color(0xFF6385C3), clicar: () async { - bool succes = await tarefaController.saveTarefa(); + bool succes = await habitoController.saveHabito(); if (succes == true) { var nav = Navigator.of(context); nav.pop(); - if (tarefa?.id != null) { + if (habito?.id != null) { //nav.pop(); nav.pop(); } diff --git a/lib/components/dialogs/habitos/habitoDialog.dart b/lib/components/dialogs/habitos/habitoDialog.dart new file mode 100644 index 0000000..100a1e2 --- /dev/null +++ b/lib/components/dialogs/habitos/habitoDialog.dart @@ -0,0 +1,86 @@ +import 'package:flutter/material.dart'; +import 'package:organizei/Model/Habito/HabitoModel.dart'; +import 'package:organizei/Repository/HabitoRepository.dart'; +import 'package:organizei/components/botao.dart'; +import 'package:organizei/components/dialog_personalizado.dart'; +import 'package:organizei/components/dialogs/habitos/habitoCadastroDialog.dart'; +import '../../../Controller/HabitoController.dart'; + +Future visualizarHabito(BuildContext context, + {required HabitoModel habito, Function? fecharDialog = null}) { + late HabitoController habitoController; + habitoController = HabitoController(HabitoRepository(), context); + + habitoController.habitoId(habito.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: habitoController.formKey, + child: Container( + height: MediaQuery.of(context).size.height, + margin: const EdgeInsets.only(top: 24), + child: DialogPersonalizado( + nome: habito.nome ?? '', + cor: habito.cor ?? '', + child: [ + Padding( + padding: const EdgeInsets.only(bottom: 16, top: 16), + child: Botao( + texto: 'Concluir', + cor: const Color(0xFF74C198), + clicar: () async { + bool succes = + await habitoController.concluirHabito(true); + + if (succes == true) { + Navigator.pop(context); + fecharDialog!(); + } + }, + ), + ), + Botao( + texto: 'Editar', + cor: const Color(0xFF6385C3), + clicar: () async { + criarHabito(context, + habito: habito, fecharDialog: fecharDialog); + }, + ), + Padding( + padding: const EdgeInsets.only(bottom: 16, top: 16), + child: Botao( + texto: 'Excluir', + cor: const Color(0xFFEF7E69), + clicar: () async { + bool succes = + await habitoController.excluirHabito(); + + if (succes == true) { + Navigator.pop(context); + fecharDialog!(); + } + }, + ), + ), + ], + ), + ), + ), + ), + ), + ); + }); + }); +} diff --git a/lib/components/dialogs/tarefaCadastroDialog.dart b/lib/components/dialogs/tarefas/tarefaCadastroDialog.dart similarity index 98% rename from lib/components/dialogs/tarefaCadastroDialog.dart rename to lib/components/dialogs/tarefas/tarefaCadastroDialog.dart index f2be85c..e09f039 100644 --- a/lib/components/dialogs/tarefaCadastroDialog.dart +++ b/lib/components/dialogs/tarefas/tarefaCadastroDialog.dart @@ -7,7 +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 '../../Controller/TarefaController.dart'; +import '../../../Controller/TarefaController.dart'; Future criarTarefa(BuildContext context, {TarefaModel? tarefa = null, Function? fecharDialog = null}) { diff --git a/lib/components/dialogs/tarefaDialog.dart b/lib/components/dialogs/tarefas/tarefaDialog.dart similarity index 97% rename from lib/components/dialogs/tarefaDialog.dart rename to lib/components/dialogs/tarefas/tarefaDialog.dart index 0e65bad..d8e7e11 100644 --- a/lib/components/dialogs/tarefaDialog.dart +++ b/lib/components/dialogs/tarefas/tarefaDialog.dart @@ -3,8 +3,8 @@ 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/tarefaCadastroDialog.dart'; -import '../../Controller/TarefaController.dart'; +import 'package:organizei/components/dialogs/tarefas/tarefaCadastroDialog.dart'; +import '../../../Controller/TarefaController.dart'; Future visualizarTarefa(BuildContext context, {required TarefaModel tarefa, Function? fecharDialog = null}) { diff --git a/lib/components/navigation/menu.dart b/lib/components/navigation/menu.dart index 8a8881e..a7e4103 100644 --- a/lib/components/navigation/menu.dart +++ b/lib/components/navigation/menu.dart @@ -1,7 +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'; +import 'package:organizei/components/dialogs/tarefas/tarefaCadastroDialog.dart'; +import 'package:organizei/components/dialogs/habitos/habitoCadastroDialog.dart'; class Menu extends StatefulWidget { const Menu({Key? key, this.fecharMenu, this.fecharDialog = null}) @@ -194,7 +194,7 @@ class _MenuState extends State { ), GestureDetector( onTap: () { - criarHabito(context); + criarHabito(context, fecharDialog: widget.fecharDialog); widget.fecharMenu!(); }, child: AbsorbPointer( diff --git a/lib/components/selectDias.dart b/lib/components/selectDias.dart index a23ed38..4675a97 100644 --- a/lib/components/selectDias.dart +++ b/lib/components/selectDias.dart @@ -3,8 +3,11 @@ 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 = ''}) + final List? diaAtual; + const SelectDia( + {Key? key, + required this.dia, + this.diaAtual = const ['0', '0', '0', '0', '0', '0', '0']}) : super(key: key); @override @@ -12,14 +15,15 @@ class SelectDia extends StatefulWidget { } class _SelectDiaState extends State { - List dias = ['D', 'S', 'T', 'Q', 'Q', 'S', 'S']; + List dias = ['d', 's', 't', 'q', 'q', 's', 's']; + List? teste = ['0', '0', '0', '0', '0', '0', '0']; late String diaSelected = ''; @override void initState() { super.initState(); - diaSelected = widget.diaAtual; + teste = widget.diaAtual!; } @override @@ -29,7 +33,7 @@ class _SelectDiaState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( - 'dia', + 'repetir', style: TextStyle( color: Colors.black, fontSize: 16, @@ -39,24 +43,27 @@ class _SelectDiaState extends State { Padding( padding: const EdgeInsets.only(bottom: 16), child: SizedBox( - height: 50, + height: 45, child: ListView( itemExtent: 50.0, scrollDirection: Axis.horizontal, - children: dias.map((dia) { + children: dias.asMap().entries.map((dia) { return GestureDetector( onTap: () { setState(() { - diaSelected = dia; + teste![dia.key] = teste![dia.key] == '1' ? '0' : '1'; }); - widget.dia(diaSelected.toString()); + widget.dia(teste); + //widget.dia(teste)); }, child: Container( width: 20, height: 20, decoration: BoxDecoration( shape: BoxShape.circle, - color: Color(0xFFE9E9E9), + color: teste![dia.key] == '1' + ? const Color(0xFF74C198) + : const Color(0xFFE9E9E9), border: Border.all( width: 3, color: Colors.black, @@ -65,19 +72,14 @@ class _SelectDiaState extends State { child: Align( alignment: Alignment.center, child: Text( - dia, + dia.value, textAlign: TextAlign.center, style: TextStyle( color: Colors.black, fontWeight: FontWeight.w700, ), ), - ) - // ),Text( - // dia, - // textAlign: TextAlign.center, - // ), - ), + )), ); }).toList(), ), diff --git a/lib/home_page.dart b/lib/home_page.dart index 52f7d5e..6627394 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,11 +1,14 @@ import 'package:flutter/material.dart'; +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/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/tarefaDialog.dart'; +import 'package:organizei/components/dialogs/habitos/habitoDialog.dart'; +import 'package:organizei/components/dialogs/tarefas/tarefaDialog.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'components/box.dart'; @@ -155,7 +158,7 @@ class _HomePageState extends State { ), ), FutureBuilder( - future: tarefaController.getTarefas(), + future: tarefaController.get(), builder: (context, AsyncSnapshot snapshot) { if (!snapshot.hasData) { return const Center( @@ -178,9 +181,39 @@ class _HomePageState extends State { return ListView.builder( primary: false, shrinkWrap: true, - itemCount: snapshot.data.length, + itemCount: snapshot.data['tarefas'].length, itemBuilder: (context, index) { - TarefaModel item = snapshot.data[index]; + var item; + + //var dialog; + + var tipo = snapshot.data['tarefas'][index] + ['tipo']; + if (tipo == 'tarefa') { + item = TarefaModel.fromJson( + snapshot.data['tarefas'][index]); + + // dialog = visualizarTarefa( + // context, + // tarefa: item, + // fecharDialog: () { + // setState(() {}); + // }, + // ); + } + + if (tipo == 'habito') { + item = HabitoModel.fromJson( + snapshot.data['tarefas'][index]); + + // dialog = visualizarHabito( + // context, + // habito: item, + // fecharDialog: () { + // setState(() {}); + // }, + // ); + } return cardItem( cor: Color(int.tryParse( item.cor ?? '0xFF6385C3') ?? @@ -188,20 +221,22 @@ class _HomePageState extends State { nome: item.nome, horario: item.data, abrirDialog: () { - visualizarTarefa( - context, - tarefa: item, - fecharDialog: () { - setState(() {}); - }, - ); - // criarTarefa( - // context, - // tarefa: item, - // fecharDialog: () { - // setState(() {}); - // }, - // ); + if (tipo == 'tarefa') + return visualizarTarefa( + context, + tarefa: item, + fecharDialog: () { + setState(() {}); + }, + ); + else if (tipo == 'habito') + return visualizarHabito( + context, + habito: item, + fecharDialog: () { + setState(() {}); + }, + ); }); }); }), @@ -214,12 +249,6 @@ class _HomePageState extends State { ), ), ), - - // floatingActionButton: FloatingActionButton( - // onPressed: _incrementCounter, - // tooltip: 'Increment', - // child: const Icon(Icons.add), - // ), floatingActionButton: ButtonNavigatorBar( fecharDialog: () { setState(() {});