Skip to content

Commit

Permalink
mexi em coisas bei
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrcode committed Sep 30, 2022
1 parent f95ac22 commit 982f7a3
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 131 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/SplashController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SplashController extends Base {
String? apelido = prefs.getString('UsuarioApelido');

if (login != null) {
return HomePage(apelido: apelido);
return HomePage();
} else
return StartPage();
}
Expand Down
40 changes: 40 additions & 0 deletions lib/Controller/TarefaController.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,44 @@ class TarefaController extends Base {
Future<List<TarefaModel>?> getTarefas() async {
return await repository.getTarefas();
}

Future<bool> concluirTarefa(bool concluido) async {
try {
return await repository
.concluirTarefa(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;
}
}
}
17 changes: 15 additions & 2 deletions lib/Repository/TarefaRepository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class TarefaRepository {
"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,
Expand All @@ -41,6 +39,21 @@ class TarefaRepository {
return ResponseAPIModel.fromJson(jsonDecode(response.body));
}

Future<ResponseAPIModel> concluirTarefa(
TarefaModel model, bool concluido) async {
var json = {
"concluido": concluido,
};

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

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

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

Expand Down
4 changes: 3 additions & 1 deletion lib/components/dialog_personalizado.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ class DialogPersonalizado extends StatefulWidget {
Key? key,
required this.child,
required this.nome,
this.cor = '',
}) : super(key: key);

final List<Widget> child;
final String nome;
final String cor;

@override
State<DialogPersonalizado> createState() => _DialogPersonalizadoState();
Expand Down Expand Up @@ -81,7 +83,7 @@ class _DialogPersonalizadoState extends State<DialogPersonalizado>
TextoContornado(
texto: widget.nome,
tamanho: 32,
cor: const Color(0xFF6385C3),
cor: Color(int.tryParse(widget.cor) ?? 0xFF6385C3),
),
],
),
Expand Down
9 changes: 8 additions & 1 deletion lib/components/dialogs/tarefaCadastroDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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,
Expand Down Expand Up @@ -78,7 +79,13 @@ Future<dynamic> criarTarefa(BuildContext context,
bool succes = await tarefaController.saveTarefa();

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

if (tarefa?.id != null) {
//nav.pop();
nav.pop();
}
fecharDialog!();
}
},
Expand Down
66 changes: 48 additions & 18 deletions lib/components/dialogs/tarefaDialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,14 @@ 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> visualizarTarefa(BuildContext context,
{required TarefaModel tarefa, Function? fecharDialog = null}) {
late TarefaController tarefaController;
//setState(() {
tarefaController = TarefaController(TarefaRepository(), context);

// });
tarefaController.tarefaId(tarefa.id);

return showDialog(
barrierDismissible: false,
Expand All @@ -37,25 +32,60 @@ Future<dynamic> visualizarTarefa(BuildContext context,
margin: const EdgeInsets.only(top: 24),
child: DialogPersonalizado(
nome: tarefa.nome ?? '',
cor: tarefa.cor ?? '',
child: <Widget>[
Botao(
texto: 'Concluir',
cor: const Color(0xFF74C198),
clicar: () async {
// bool succes = await tarefaController.saveTarefa();
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!();
// }
},
if (succes == true) {
Navigator.pop(context);
fecharDialog!();
}
},
),
),
Botao(
texto: 'Editar',
cor: const Color(0xFF6385C3),
clicar: () async {
Navigator.pop(context);
criarTarefa(context, tarefa: tarefa);
// Navigator.pop(context);
criarTarefa(context,
tarefa: tarefa, fecharDialog: fecharDialog);

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

Expand Down
19 changes: 8 additions & 11 deletions lib/components/input.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flutter/material.dart';

Widget input(
{dynamic onSaved,
TextEditingController? textController,
String? label,
bool senha = false,
bool readOnly = false,
String? placeholder = '',
Function? customFunction}) {
Widget input({
dynamic onSaved,
TextEditingController? textController,
String? label,
bool senha = false,
bool readOnly = false,
String? placeholder = '',
}) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -24,9 +24,6 @@ Widget input(
color: Colors.white.withOpacity(0),
child: TextFormField(
obscureText: senha,
onTap: () {
return customFunction!();
},
readOnly: readOnly,
onSaved: onSaved,
controller: textController,
Expand Down
Loading

0 comments on commit 982f7a3

Please sign in to comment.