Skip to content

Commit

Permalink
Listas
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Oct 14, 2022
1 parent 43e074d commit 0099dbd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 28 deletions.
3 changes: 2 additions & 1 deletion lib/Model/API/APIModel.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class ApiModel {
static const ApiUrl = "http://10.0.0.91: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
53 changes: 34 additions & 19 deletions lib/components/dialogs/listas/listaCadastroDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ 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;
late List<TextEditingController> _controllers = [new TextEditingController()];

listaController = ListaController(ListaRepository(), context);

Expand Down Expand Up @@ -63,18 +62,23 @@ Future<dynamic> criarLista(BuildContext context,
shrinkWrap: true,
itemCount: itens.length,
itemBuilder: (context, index) {
var item;

//var dialog;

var controllerNomeItem = TextEditingController();
// var controllerNomeItem = TextEditingController();

return Padding(
padding: const EdgeInsets.only(bottom: 16),
child: input(
//onSaved: listaController.listaNome,
textController: controllerNomeItem,
textController: _controllers[index],
label: 'item',
excluir: true,
funcao: () {
setState(() {
itens.remove(itens[index]);
_controllers.remove(_controllers[index]);
});
},
),
);
}),
Expand All @@ -86,6 +90,7 @@ Future<dynamic> criarLista(BuildContext context,
clicar: () async {
setState(() {
itens.add(ItemModel());
_controllers.add(new TextEditingController());
});

// bool succes = await listaController.saveLista();
Expand All @@ -103,23 +108,33 @@ Future<dynamic> criarLista(BuildContext context,
},
),
),
Botao(
texto: 'Salvar',
cor: const Color(0xFF6385C3),
clicar: () async {
bool succes = await listaController.saveLista();
Padding(
padding: const EdgeInsets.only(bottom: 16),
child: Botao(
texto: 'Salvar',
cor: const Color(0xFF6385C3),
clicar: () async {
List<ItemModel?>? listaitens = [];

if (succes == true) {
var nav = Navigator.of(context);
nav.pop();
_controllers.map((item) {
listaitens.add(ItemModel(nome: (item.text)));
}).toList();

if (lista?.id != null) {
//nav.pop();
listaController.listaItens(listaitens);
bool succes = await listaController.saveLista();

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

if (lista?.id != null) {
//nav.pop();
nav.pop();
}
fecharDialog!();
}
fecharDialog!();
}
},
},
),
),
],
),
Expand Down
24 changes: 16 additions & 8 deletions lib/components/input.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'package:flutter/material.dart';

Widget input({
dynamic onSaved,
TextEditingController? textController,
String? label,
bool senha = false,
bool readOnly = false,
String? placeholder = '',
}) {
Widget input(
{dynamic onSaved,
TextEditingController? textController,
String? label,
bool senha = false,
bool readOnly = false,
String? placeholder = '',
bool excluir = false,
Function? funcao}) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -28,6 +29,13 @@ Widget input({
onSaved: onSaved,
controller: textController,
decoration: InputDecoration(
suffixIcon: excluir
? GestureDetector(
onTap: () {
funcao!();
},
child: const Icon(Icons.close))
: null,
hintText: placeholder,
fillColor: Colors.white,
filled: true,
Expand Down

0 comments on commit 0099dbd

Please sign in to comment.