Skip to content

Commit

Permalink
ai mexi em mt coisa viu
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Sep 29, 2022
1 parent b1cf601 commit f95ac22
Show file tree
Hide file tree
Showing 11 changed files with 371 additions and 150 deletions.
78 changes: 56 additions & 22 deletions lib/Controller/TarefaController.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'dart:ffi';

import 'package:flutter/material.dart';
import 'package:http/http.dart';
import 'package:organizei/Model/Tarefa/TarefaModel.dart';
import 'package:organizei/Controller/Base/Base.dart';
import 'package:organizei/Repository/TarefaRepository.dart';
Expand All @@ -13,6 +16,7 @@ class TarefaController extends Base {
var model = TarefaModel();
//var loginConfiguracoes = LoginConfiguracoes();

tarefaId(int? value) => model.id = value;
tarefaNome(String? value) => model.nome = value.toString();
tarefaDataehora(String? value) => model.data = value.toString();
tarefaObservacao(String? value) => model.observacao = value.toString();
Expand All @@ -35,24 +39,28 @@ class TarefaController extends Base {
try {
if (model.id == null) {
return await repository.addTarefa(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!,
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),
));
),
),
backgroundColor: value.valido!
? const Color(0xFF74C198)
: const Color(0xFFEF7E69),
),
);

await Future.delayed(const Duration(seconds: 1));
await Future.delayed(const Duration(milliseconds: 500));

if (value.valido!) {
return value.valido!;
Expand All @@ -61,18 +69,44 @@ class TarefaController extends Base {
}
});
} else {
/*return await repository.updateProduto(model).then((value) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(value.msg),
backgroundColor: value.valido ? Colors.green : Colors.red,
));
return value.valido;
});*/
return false;
return await repository.updateTarefa(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;
}
}

Future<List<TarefaModel>?> getTarefas() async {
return await repository.getTarefas();
}
}
33 changes: 33 additions & 0 deletions lib/Repository/TarefaRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,37 @@ class TarefaRepository {

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

Future<ResponseAPIModel> updateTarefa(TarefaModel model) async {
var json = {
"nome": model.nome,
"data": model.data,
"observacao": model.observacao,
"prioridade": model.prioridade,
"cor": model.cor,
};

print(ApiModel.ApiUrl + '/tarefas/' + model.id.toString());

final response = await http.put(
Uri.parse(ApiModel.ApiUrl + '/tarefas/' + model.id.toString()),
headers: ApiModel.headers,
body: jsonEncode(json));

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

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

var _url = Uri.parse(_uriSearchProduto.toString());
final response = await http.get(_url, headers: ApiModel.headers);

Map<String, dynamic> jsonMap = jsonDecode(response.body);
List<TarefaModel> listaProdutos = (jsonMap['tarefas'] as List)
.map((item) => TarefaModel.fromJson(item))
.toList();

return listaProdutos;
}
}
6 changes: 4 additions & 2 deletions lib/components/card_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class cardItem extends StatelessWidget {
final Color? cor;
final String? horario;
final String? nome;
final Function? abrirDialog;

const cardItem({Key? key, this.cor, this.horario, this.nome})
const cardItem(
{Key? key, this.cor, this.horario, this.nome, this.abrirDialog})
: super(key: key);

String formatarNome() {
Expand Down Expand Up @@ -37,7 +39,7 @@ class cardItem extends StatelessWidget {
borderRadius: BorderRadius.all(Radius.circular(21)),
child: GestureDetector(
onTap: () {
debugPrint(nome);
abrirDialog!();
},
child: Row(
children: [
Expand Down
2 changes: 1 addition & 1 deletion lib/components/dialog_personalizado.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _DialogPersonalizadoState extends State<DialogPersonalizado>
child: const Icon(Icons.close),
onTap: () {
_slideDown();
Future.delayed(Duration(milliseconds: 500))
Future.delayed(const Duration(milliseconds: 500))
.then((value) => Navigator.pop(context));
},
),
Expand Down
95 changes: 95 additions & 0 deletions lib/components/dialogs/tarefaCadastroDialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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/selectPrioridade.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) {
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: 'Tarefa',
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',
),
),
SelectPrioridade(
prioridade: tarefaController.tarefaPrioridade,
prioridadeAtual: tarefa?.prioridade ?? ''),
SelectCor(
cor: tarefaController.tarefaCor,
corAtual: tarefa?.cor ?? ''),
Botao(
texto: 'Salvar',
cor: const Color(0xFF6385C3),
clicar: () async {
bool succes = await tarefaController.saveTarefa();

if (succes == true) {
Navigator.pop(context);
fecharDialog!();
}
},
),
],
),
),
),
),
),
);
});
});
}
56 changes: 27 additions & 29 deletions lib/components/dialogs/tarefaDialog.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
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/tarefaCadastroDialog.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/TarefaController.dart';

Future<dynamic> criarTarefa(BuildContext context) {
Future<dynamic> visualizarTarefa(BuildContext context,
{required TarefaModel tarefa, Function? fecharDialog = null}) {
late TarefaController tarefaController;
//setState(() {
tarefaController = TarefaController(TarefaRepository(), context);

// });

return showDialog(
Expand All @@ -29,42 +33,36 @@ Future<dynamic> criarTarefa(BuildContext context) {
child: Form(
key: tarefaController.formKey,
child: Container(
height: MediaQuery.of(context).size.height,
margin: const EdgeInsets.only(top: 24),
child: DialogPersonalizado(
nome: 'Tarefa',
nome: tarefa.nome ?? '',
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',
),
Botao(
texto: 'Concluir',
cor: const Color(0xFF74C198),
clicar: () async {
// bool succes = await tarefaController.saveTarefa();

// if (succes == true) {
// Navigator.pop(context);
// fecharDialog!();
// }
},
),
SelectPrioridade(
prioridade: tarefaController.tarefaPrioridade),
SelectCor(cor: tarefaController.tarefaCor),
Botao(
texto: 'Cadastrar',
texto: 'Editar',
cor: const Color(0xFF6385C3),
clicar: () async {
bool succes = await tarefaController.saveTarefa();
Navigator.pop(context);
criarTarefa(context, tarefa: tarefa);

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

if (succes == true) {
Navigator.pop(context);
}
// if (succes == true) {
// Navigator.pop(context);
// fecharDialog!();
// }
},
),
],
Expand Down
10 changes: 8 additions & 2 deletions lib/components/navigation/bottom_navigation_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import 'package:organizei/components/navigation/menu.dart';
import '../box.dart';

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

final Function? fecharDialog;

@override
State<ButtonNavigatorBar> createState() => _ButtonNavigatorBarState();
Expand Down Expand Up @@ -49,7 +52,10 @@ class _ButtonNavigatorBarState extends State<ButtonNavigatorBar>
offset: offset,
duration: const Duration(milliseconds: 250),
curve: Curves.easeInOut,
child: Container(child: Menu(fecharMenu: _slideDown)),
child: Container(
child: Menu(
fecharMenu: _slideDown,
fecharDialog: widget.fecharDialog)),
),
Box(
radius: 30,
Expand Down
Loading

0 comments on commit f95ac22

Please sign in to comment.