Skip to content

Commit

Permalink
Listas
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Oct 13, 2022
1 parent 59dc853 commit 43e074d
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 109 deletions.
133 changes: 133 additions & 0 deletions lib/components/dialogs/listas/listaCadastroDialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import 'package:flutter/material.dart';
import 'package:organizei/Model/Item/ItemModel.dart';
import 'package:organizei/Model/Lista/ListaModel.dart';
import 'package:organizei/Repository/ListaRepository.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/ListaController.dart';

Future<dynamic> criarLista(BuildContext context,
{ListaModel? lista = null, Function? fecharDialog = null}) {
late ListaController listaController;

listaController = ListaController(ListaRepository(), context);

late List<ItemModel?>? itens = [ItemModel()];

if (lista != null) {
listaController.controllerNome.text = lista.nome ?? '';
listaController.listaCor(lista.cor);
listaController.listaId(lista.id);
listaController.listaItens(lista.itens);
}

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: listaController.formKey,
child: Container(
margin: const EdgeInsets.only(top: 24),
height: itens.length < 3
? MediaQuery.of(context).size.height
: null,
child: DialogPersonalizado(
nome: 'Lista',
child: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: input(
onSaved: listaController.listaNome,
textController: listaController.controllerNome,
label: 'nome',
),
),
SelectCor(
cor: listaController.listaCor,
corAtual: lista?.cor ?? ''),
ListView.builder(
primary: false,
shrinkWrap: true,
itemCount: itens.length,
itemBuilder: (context, index) {
var item;

//var dialog;

var controllerNomeItem = TextEditingController();

return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: input(
//onSaved: listaController.listaNome,
textController: controllerNomeItem,
label: 'item',
),
);
}),
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Botao(
texto: 'Novo item',
cor: const Color(0xFF6BC8E4),
clicar: () async {
setState(() {
itens.add(ItemModel());
});

// bool succes = await listaController.saveLista();

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

// if (lista?.id != null) {
// //nav.pop();
// nav.pop();
// }
// fecharDialog!();
// }
},
),
),
Botao(
texto: 'Salvar',
cor: const Color(0xFF6385C3),
clicar: () async {
bool succes = await listaController.saveLista();

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

if (lista?.id != null) {
//nav.pop();
nav.pop();
}
fecharDialog!();
}
},
),
],
),
),
),
),
),
);
});
});
}
115 changes: 115 additions & 0 deletions lib/components/dialogs/listas/listaDialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
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<dynamic> visualizarTarefa(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: Container(
height: MediaQuery.of(context).size.height,
margin: const EdgeInsets.only(top: 24),
child: DialogPersonalizado(
nome: tarefa.nome ?? '',
cor: tarefa.cor ?? '',
child: <Widget>[
Text(tarefa.observacao ?? ''),
Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Text(
'data: ',
style: TextStyle(
color: Colors.black,
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 ?? ''),
],
),
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!();
}
},
),
),
],
),
),
),
),
),
);
});
});
}
111 changes: 2 additions & 109 deletions lib/components/navigation/menu.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:organizei/components/dialog_personalizado.dart';
import 'package:organizei/components/dialogs/listas/listaCadastroDialog.dart';
import 'package:organizei/components/dialogs/tarefas/tarefaCadastroDialog.dart';
import 'package:organizei/components/dialogs/habitos/habitoCadastroDialog.dart';

Expand Down Expand Up @@ -42,118 +43,10 @@ class _MenuState extends State<Menu> {
children: [
GestureDetector(
onTap: () {
criarLista(context, fecharDialog: widget.fecharDialog);
widget.fecharMenu!();
showDialog(
barrierDismissible: false,
barrierColor: Colors.white.withOpacity(0),
context: context,
builder: (context) {
return Container(
margin: EdgeInsets.only(top: 24),
child: DialogPersonalizado(
nome: 'Lista',
//minHeight: MediaQuery.of(context).size.height * 0.8,
child: <Widget>[
Text(
'nome',
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
Material(
color: Colors.white.withOpacity(0),
child: TextField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.black,
width: 3.0,
),
borderRadius: BorderRadius.circular(16.0),
),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.black,
width: 3.0,
),
borderRadius: BorderRadius.circular(16.0),
),

//labelText: 'Password',
),
),
),
Text(
'item',
style: const TextStyle(
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.w400,
),
),
Material(
color: Colors.white.withOpacity(0),
child: TextField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.black,
width: 3.0,
),
borderRadius: BorderRadius.circular(16.0),
),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.black,
width: 3.0,
),
borderRadius: BorderRadius.circular(16.0),
),

//labelText: 'Password',
),
),
),
SizedBox(
width: double.maxFinite,
height: 60,
child: ElevatedButton(
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(16.0),
// side: BorderSide(color: Colors.red)
)),
side: MaterialStateProperty.all(
BorderSide(
width: 3, color: Colors.black)),
backgroundColor:
MaterialStateProperty.all(
Color(0xFF6385C3)),
),
child: Text(
'SALVAR',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold),
),
onPressed: () {}),
),
],
),
);
});
},
child: AbsorbPointer(
//width: MediaQuery.of(context).size.width,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
Expand Down

0 comments on commit 43e074d

Please sign in to comment.