Skip to content

Commit

Permalink
Lista
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Oct 14, 2022
1 parent 63f2b18 commit b2fa4e1
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 126 deletions.
64 changes: 64 additions & 0 deletions lib/Controller/ItemController.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:organizei/Model/Item/ItemModel.dart';
import 'package:organizei/Controller/Base/Base.dart';
import 'package:organizei/Repository/ItemRepository.dart';
import 'package:organizei/services/persistencia/login.configuracoes.dart';

class ItemController extends Base {
ItemController(this.repository, this.context);

final BuildContext context;
final ItemRepository repository;
final formKey = GlobalKey<FormState>();
var model = ItemModel();
//var loginConfiguracoes = LoginConfiguracoes();

itemId(int? value) => model.id = value;
itemNome(String? value) => model.nome = value.toString();
itemConcluido(bool? value) => model.concluido = value;

var controllerNome = TextEditingController();

Future<bool> concluirItem(bool? concluido) async {
try {
return await repository
.concluirItem(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;
}
}
}
4 changes: 2 additions & 2 deletions lib/Model/API/APIModel.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class ApiModel {
//static const ApiUrl = "http://10.0.0.91:4444";
static const ApiUrl = "http://192.168.100.74:4444";
static const ApiUrl = "http://10.0.0.91:4444";
//static const ApiUrl = "http://192.168.100.74:4444";
// static const ApiUrl = "http://189.10.2.165:4444";
static const String _token = "fd7bc88b7c0149adbc134d5d0a919814";
static const Map<String, String> headers = {
Expand Down
15 changes: 14 additions & 1 deletion lib/Model/Lista/ListaModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ class ListaModel {
id = int.parse(json['id']);
nome = json['nome'];
cor = json['cor'];
itens = json['itens'];

List<ItemModel> listaItens = [];
json['item'].map((item) {
listaItens.add(ItemModel(
nome: item['nome'],
concluido: item['concluido'],
id: int.parse(item['id'])));
}).toList();

itens = listaItens;

// _controllers.map((item) {
// listaitens.add(ItemModel(nome: (item.text)));
// }).toList();
}

Map<String, dynamic> toJson() {
Expand Down
16 changes: 13 additions & 3 deletions lib/components/dialogs/listas/listaCadastroDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ Future<dynamic> criarLista(BuildContext context,
listaController.listaCor(lista.cor);
listaController.listaId(lista.id);
listaController.listaItens(lista.itens);

itens = [];

itens = lista.itens;

itens!.map((item) {
var controllerNome = TextEditingController();
controllerNome.text = (item!.nome ?? '');
_controllers.add(controllerNome);
}).toList();
}

return showDialog(
Expand All @@ -40,7 +50,7 @@ Future<dynamic> criarLista(BuildContext context,
key: listaController.formKey,
child: Container(
margin: const EdgeInsets.only(top: 24),
height: itens.length < 3
height: itens!.length < 3
? MediaQuery.of(context).size.height
: null,
child: DialogPersonalizado(
Expand Down Expand Up @@ -75,7 +85,7 @@ Future<dynamic> criarLista(BuildContext context,
excluir: true,
funcao: () {
setState(() {
itens.remove(itens[index]);
itens!.remove(itens[index]);
_controllers.remove(_controllers[index]);
});
},
Expand All @@ -89,7 +99,7 @@ Future<dynamic> criarLista(BuildContext context,
cor: const Color(0xFF6BC8E4),
clicar: () async {
setState(() {
itens.add(ItemModel());
itens!.add(ItemModel());
_controllers.add(new TextEditingController());
});

Expand Down
110 changes: 51 additions & 59 deletions lib/components/dialogs/listas/listaDialog.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import 'package:flutter/material.dart';
import 'package:organizei/Model/Tarefa/TarefaModel.dart';
import 'package:organizei/Repository/TarefaRepository.dart';
import 'package:organizei/Controller/ItemController.dart';
import 'package:organizei/Model/Item/ItemModel.dart';
import 'package:organizei/Model/Lista/ListaModel.dart';
import 'package:organizei/Repository/ItemRepository.dart';
import 'package:organizei/Repository/ListaRepository.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/listas/listaCadastroDialog.dart';
import '../../../Controller/ListaController.dart';

Future<dynamic> visualizarTarefa(BuildContext context,
{required TarefaModel tarefa, Function? fecharDialog = null}) {
late TarefaController tarefaController;
tarefaController = TarefaController(TarefaRepository(), context);
Future<dynamic> visualizarLista(BuildContext context,
{required ListaModel lista, Function? fecharDialog = null}) {
late ListaController listaController;
late ItemController itemController;
listaController = ListaController(ListaRepository(), context);
itemController = ItemController(ItemRepository(), context);

tarefaController.tarefaId(tarefa.id);
listaController.listaId(lista.id);

return showDialog(
barrierDismissible: false,
Expand All @@ -26,65 +31,52 @@ Future<dynamic> visualizarTarefa(BuildContext context,
child: Material(
type: MaterialType.transparency,
child: Form(
key: tarefaController.formKey,
key: listaController.formKey,
child: Container(
height: MediaQuery.of(context).size.height,
margin: const EdgeInsets.only(top: 24),
child: DialogPersonalizado(
nome: tarefa.nome ?? '',
cor: tarefa.cor ?? '',
nome: lista.nome ?? '',
cor: lista.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);
ListView.builder(
//primary: false,
shrinkWrap: true,
itemCount: lista.itens!.length,
itemBuilder: (context, index) {
var item = ItemModel(
id: lista.itens![index]!.id,
nome: lista.itens![index]!.nome,
concluido: lista.itens![index]!.concluido,
);

if (succes == true) {
Navigator.pop(context);
fecharDialog!();
}
},
),
),
return Row(
children: [
Checkbox(
value: lista.itens![index]!.concluido,
onChanged: (bool? value) async {
setState(() {
lista.itens![index]!.concluido = value!;
});
itemController.itemId(item.id);
await itemController.concluirItem(
lista.itens![index]!.concluido);
},
),
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Text(
lista.itens![index]!.nome.toString()),
),
],
);
}),
Botao(
texto: 'Editar',
cor: const Color(0xFF6385C3),
clicar: () async {
criarTarefa(context,
tarefa: tarefa, fecharDialog: fecharDialog);
criarLista(context,
lista: lista, fecharDialog: fecharDialog);
},
),
Padding(
Expand All @@ -94,7 +86,7 @@ Future<dynamic> visualizarTarefa(BuildContext context,
cor: const Color(0xFFEF7E69),
clicar: () async {
bool succes =
await tarefaController.excluirTarefa();
await listaController.excluirLista();

if (succes == true) {
Navigator.pop(context);
Expand Down
21 changes: 11 additions & 10 deletions lib/components/navigation/bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import 'package:organizei/listas_page.dart';
import '../box.dart';

class ButtonNavigatorBar extends StatefulWidget {
const ButtonNavigatorBar({Key? key, this.fecharDialog = null})
ButtonNavigatorBar(
{Key? key, this.fecharDialog = null, this.iconSelected = 'home'})
: super(key: key);

final Function? fecharDialog;
late String? iconSelected;

@override
State<ButtonNavigatorBar> createState() => _ButtonNavigatorBarState();
Expand All @@ -18,7 +20,6 @@ class ButtonNavigatorBar extends StatefulWidget {
class _ButtonNavigatorBarState extends State<ButtonNavigatorBar>
with SingleTickerProviderStateMixin {
bool addIcone = false;
String iconSelected = 'home';

Offset offset = const Offset(0, 2);

Expand Down Expand Up @@ -70,13 +71,13 @@ class _ButtonNavigatorBarState extends State<ButtonNavigatorBar>
IconButton(
icon: Icon(
Icons.home_outlined,
color: iconSelected == 'home'
color: widget.iconSelected == 'home'
? const Color(0xFFF7BC36)
: Colors.black,
),
onPressed: () {
setState(() {
iconSelected = 'home';
widget.iconSelected = 'home';
});
Navigator.of(context).push<void>(
MaterialPageRoute<void>(
Expand All @@ -88,13 +89,13 @@ class _ButtonNavigatorBarState extends State<ButtonNavigatorBar>
IconButton(
icon: Icon(
Icons.bar_chart_outlined,
color: iconSelected == 'dashboard'
color: widget.iconSelected == 'dashboard'
? const Color(0xFFF7BC36)
: Colors.black,
),
onPressed: () {
setState(() {
iconSelected = 'dashboard';
widget.iconSelected = 'dashboard';
});
},
),
Expand Down Expand Up @@ -127,13 +128,13 @@ class _ButtonNavigatorBarState extends State<ButtonNavigatorBar>
IconButton(
icon: Icon(
Icons.list_outlined,
color: iconSelected == 'listas'
color: widget.iconSelected == 'listas'
? const Color(0xFFF7BC36)
: Colors.black,
),
onPressed: () {
setState(() {
iconSelected = 'listas';
widget.iconSelected = 'listas';
});
Navigator.push(
context,
Expand All @@ -150,13 +151,13 @@ class _ButtonNavigatorBarState extends State<ButtonNavigatorBar>
IconButton(
icon: Icon(
Icons.folder_outlined,
color: iconSelected == 'projetos'
color: widget.iconSelected == 'projetos'
? const Color(0xFFF7BC36)
: Colors.black,
),
onPressed: () {
setState(() {
iconSelected = 'projetos';
widget.iconSelected = 'projetos';
});
},
),
Expand Down
Loading

0 comments on commit b2fa4e1

Please sign in to comment.