Skip to content

Commit

Permalink
lembretes
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Oct 15, 2022
1 parent 6c0fd28 commit 311c6ad
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 37 deletions.
40 changes: 40 additions & 0 deletions lib/Controller/LembreteController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,46 @@ class LembreteController extends Base {
return await repository.get();
}

Future<bool> 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<bool> excluirLembrete() async {
try {
return await repository.excluirLembrete(model).then((value) async {
Expand Down
17 changes: 17 additions & 0 deletions lib/Repository/LembreteRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ class LembreteRepository {
return listaLembretes;
}

Future<ResponseAPIModel> 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<Map<String, dynamic>> get() async {
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes');

Expand Down
5 changes: 2 additions & 3 deletions lib/components/dialogs/lembretes/lembreteCadastroDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ Future<dynamic> criarLembrete(BuildContext context,
setState(() {
eAniversario = value;
});

lembreteController
.lembreteAniversario(eAniversario);
},
),
),
Expand All @@ -96,6 +93,8 @@ Future<dynamic> criarLembrete(BuildContext context,
texto: 'Salvar',
cor: const Color(0xFF6385C3),
clicar: () async {
lembreteController
.lembreteAniversario(eAniversario);
bool succes =
await lembreteController.saveLembrete();

Expand Down
53 changes: 19 additions & 34 deletions lib/components/dialogs/lembretes/lembreteDialog.dart
Original file line number Diff line number Diff line change
@@ -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<dynamic> visualizarTarefa(BuildContext context,
{required TarefaModel tarefa, Function? fecharDialog = null}) {
late TarefaController tarefaController;
tarefaController = TarefaController(TarefaRepository(), context);
Future<dynamic> 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,
Expand All @@ -26,18 +26,17 @@ Future<dynamic> 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(
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height,
),
child: DialogPersonalizado(
nome: tarefa.nome ?? '',
cor: tarefa.cor ?? '',
nome: lembrete.nome ?? '',
cor: lembrete.cor ?? '',
child: <Widget>[
Text(tarefa.observacao ?? ''),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -49,21 +48,7 @@ Future<dynamic> visualizarTarefa(BuildContext context,
fontWeight: FontWeight.w700,
),
),
Text(tarefa.data ?? ''),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'prioridade: ',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.w700,
),
),
Text(tarefa.prioridade ?? ''),
Text(lembrete.data ?? ''),
],
),
Padding(
Expand All @@ -72,9 +57,8 @@ Future<dynamic> 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!();
Expand All @@ -86,8 +70,9 @@ Future<dynamic> visualizarTarefa(BuildContext context,
texto: 'Editar',
cor: const Color(0xFF6385C3),
clicar: () async {
criarTarefa(context,
tarefa: tarefa, fecharDialog: fecharDialog);
criarLembrete(context,
lembrete: lembrete,
fecharDialog: fecharDialog);
},
),
Padding(
Expand All @@ -97,7 +82,7 @@ Future<dynamic> visualizarTarefa(BuildContext context,
cor: const Color(0xFFEF7E69),
clicar: () async {
bool succes =
await tarefaController.excluirTarefa();
await lembreteController.excluirLembrete();

if (succes == true) {
Navigator.pop(context);
Expand Down
15 changes: 15 additions & 0 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -198,6 +200,11 @@ class _HomePageState extends State<HomePage> {
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') ??
Expand All @@ -222,6 +229,14 @@ class _HomePageState extends State<HomePage> {
setState(() {});
},
);
} else if (tipo == 'lembrete') {
return visualizarLembrete(
context,
lembrete: item,
fecharDialog: () {
setState(() {});
},
);
}
});
});
Expand Down

0 comments on commit 311c6ad

Please sign in to comment.