Skip to content

Commit

Permalink
select dia and habito dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Sep 30, 2022
1 parent 982f7a3 commit 5ac03a0
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 54 deletions.
38 changes: 38 additions & 0 deletions lib/Controller/TarefaController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,42 @@ class TarefaController extends Base {
return false;
}
}

Future<bool> excluirTarefa() async {
try {
return await repository.excluirTarefa(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;
}
}
}
8 changes: 8 additions & 0 deletions lib/Repository/TarefaRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ class TarefaRepository {
return ResponseAPIModel.fromJson(jsonDecode(response.body));
}

Future<ResponseAPIModel> excluirTarefa(TarefaModel model) async {
final response = await http.delete(
Uri.parse(ApiModel.ApiUrl + '/tarefas/' + model.id.toString()),
headers: ApiModel.headers);

return ResponseAPIModel.fromJson(jsonDecode(response.body));
}

Future<List<TarefaModel>> getTarefas() async {
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/tarefas');

Expand Down
14 changes: 7 additions & 7 deletions lib/components/dialogs/tarefaCadastroDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ 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<dynamic> criarTarefa(BuildContext context,
{TarefaModel? tarefa = null, Function? fecharDialog = null}) {
late TarefaController tarefaController;
//setState(() {

tarefaController = TarefaController(TarefaRepository(), context);

if (tarefa != null) {
Expand All @@ -25,8 +24,6 @@ Future<dynamic> criarTarefa(BuildContext context,
tarefaController.tarefaId(tarefa.id);
}

// });

return showDialog(
barrierDismissible: false,
barrierColor: Colors.white.withOpacity(0),
Expand Down Expand Up @@ -66,9 +63,12 @@ Future<dynamic> criarTarefa(BuildContext context,
label: 'observação',
),
),
SelectPrioridade(
prioridade: tarefaController.tarefaPrioridade,
prioridadeAtual: tarefa?.prioridade ?? ''),
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: SelectPrioridade(
prioridade: tarefaController.tarefaPrioridade,
prioridadeAtual: tarefa?.prioridade ?? ''),
),
SelectCor(
cor: tarefaController.tarefaCor,
corAtual: tarefa?.cor ?? ''),
Expand Down
107 changes: 107 additions & 0 deletions lib/components/dialogs/tarefaCadastroHabito.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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/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';

Future<dynamic> criarHabito(BuildContext context,
{TarefaModel? tarefa = null, Function? fecharDialog = null}) {
late TarefaController tarefaController;

tarefaController = TarefaController(TarefaRepository(), 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);
}

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: Container(
margin: const EdgeInsets.only(top: 24),
child: DialogPersonalizado(
nome: 'Hábito',
child: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: input(
onSaved: tarefaController.tarefaNome,
textController: tarefaController.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),
SelectCor(
cor: tarefaController.tarefaCor,
corAtual: tarefa?.cor ?? ''),
Botao(
texto: 'Salvar',
cor: const Color(0xFF6385C3),
clicar: () async {
bool succes = await tarefaController.saveTarefa();

if (succes == true) {
var nav = Navigator.of(context);
nav.pop();

if (tarefa?.id != null) {
//nav.pop();
nav.pop();
}
fecharDialog!();
}
},
),
],
),
),
),
),
),
);
});
});
}

selectDias() {}
24 changes: 16 additions & 8 deletions lib/components/dialogs/tarefaDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,26 @@ Future<dynamic> visualizarTarefa(BuildContext context,
texto: 'Editar',
cor: const Color(0xFF6385C3),
clicar: () async {
// Navigator.pop(context);
criarTarefa(context,
tarefa: tarefa, fecharDialog: fecharDialog);

// bool succes = await tarefaController.saveTarefa();

// if (succes == true) {
// Navigator.pop(context);
// 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!();
}
},
),
),
],
),
),
Expand Down
25 changes: 17 additions & 8 deletions lib/components/navigation/menu.dart
Original file line number Diff line number Diff line change
@@ -1,6 +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';

class Menu extends StatefulWidget {
const Menu({Key? key, this.fecharMenu, this.fecharDialog = null})
Expand Down Expand Up @@ -191,15 +192,23 @@ class _MenuState extends State<Menu> {
thickness: 3,
color: Colors.black,
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'criar hábito',
style: TextStyle(fontSize: 24.0),
GestureDetector(
onTap: () {
criarHabito(context);
widget.fecharMenu!();
},
child: AbsorbPointer(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'criar hábito',
style: TextStyle(fontSize: 24.0),
),
],
),
],
),
),
Divider(
thickness: 3,
Expand Down
60 changes: 29 additions & 31 deletions lib/components/selectCor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,37 +45,35 @@ class _SelectCorState extends State<SelectCor> {
),
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Expanded(
child: SizedBox(
height: 50,
child: ListView(
itemExtent: 70.0,
scrollDirection: Axis.horizontal,
children: cores.map((strone) {
return GestureDetector(
onTap: () {
setState(() {
corSelected = strone;
});
widget.cor(corSelected.toString());
},
child: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(strone),
border: Border.all(
width: corSelected == strone ? 5 : 3,
color: corSelected == strone
? Colors.white
: Colors.black,
style: BorderStyle.solid,
)),
),
);
}).toList(),
),
child: SizedBox(
height: 50,
child: ListView(
itemExtent: 70.0,
scrollDirection: Axis.horizontal,
children: cores.map((strone) {
return GestureDetector(
onTap: () {
setState(() {
corSelected = strone;
});
widget.cor(corSelected.toString());
},
child: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(strone),
border: Border.all(
width: corSelected == strone ? 5 : 3,
color: corSelected == strone
? Colors.white
: Colors.black,
style: BorderStyle.solid,
)),
),
);
}).toList(),
),
)),
],
Expand Down
Loading

0 comments on commit 5ac03a0

Please sign in to comment.