-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
516 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import 'dart:ffi'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:organizei/Model/Lembrete/LembreteModel.dart'; | ||
import 'package:organizei/Controller/Base/Base.dart'; | ||
import 'package:organizei/Repository/LembreteRepository.dart'; | ||
import 'package:organizei/services/persistencia/login.configuracoes.dart'; | ||
|
||
class LembreteController extends Base { | ||
LembreteController(this.repository, this.context); | ||
|
||
final BuildContext context; | ||
final LembreteRepository repository; | ||
final formKey = GlobalKey<FormState>(); | ||
var model = LembreteModel(); | ||
//var loginConfiguracoes = LoginConfiguracoes(); | ||
|
||
lembreteId(int? value) => model.id = value; | ||
lembreteNome(String? value) => model.nome = value.toString(); | ||
lembreteDataehora(String? value) => model.data = value.toString(); | ||
lembreteAniversario(bool? value) => model.eAniversario = value; | ||
lembreteCor(String? value) => model.cor = value.toString(); | ||
|
||
var controllerNome = TextEditingController(); | ||
var controllerCor = TextEditingController(); | ||
var controllerDataehora = TextEditingController(); | ||
|
||
Future<bool> saveLembrete() async { | ||
if (!formKey.currentState!.validate()) { | ||
return false; | ||
} | ||
|
||
formKey.currentState!.save(); | ||
|
||
try { | ||
if (model.id == null) { | ||
return await repository.addLembrete(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; | ||
} | ||
}); | ||
} else { | ||
return await repository.updateLembrete(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<LembreteModel>?> getLembretes() async { | ||
return await repository.getLembretes(); | ||
} | ||
|
||
Future<Map<String, dynamic>> get() async { | ||
return await repository.get(); | ||
} | ||
|
||
Future<bool> excluirLembrete() async { | ||
try { | ||
return await repository.excluirLembrete(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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:organizei/Model/API/ResponseAPIModel.dart'; | ||
|
||
class LembreteModel { | ||
int? id; | ||
String? nome; | ||
String? data; | ||
bool? eAniversario; | ||
String? cor; | ||
ResponseAPIModel? responseAPIModel; | ||
|
||
LembreteModel({this.id, this.nome, this.data, this.eAniversario, this.cor}); | ||
|
||
LembreteModel.fromJson(Map<String, dynamic> json) { | ||
id = int.parse(json['id']); | ||
nome = json['nome']; | ||
data = json['data']; | ||
eAniversario = json['eAniversario']; | ||
cor = json['cor']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = Map<String, dynamic>(); | ||
data['id'] = id; | ||
data['nome'] = nome; | ||
data['data'] = data; | ||
data['eAniversario'] = eAniversario; | ||
data['cor'] = cor; | ||
|
||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:organizei/Model/API/APIModel.dart'; | ||
|
||
import 'package:http/http.dart' as http; | ||
import 'package:organizei/Model/API/ResponseAPIModel.dart'; | ||
import 'package:organizei/Model/Lembrete/LembreteModel.dart'; | ||
|
||
class LembreteRepository { | ||
Future<ResponseAPIModel> addLembrete(LembreteModel model) async { | ||
var json = { | ||
"nome": model.nome, | ||
"data": model.data, | ||
"eAniversario": model.eAniversario, | ||
"cor": model.cor, | ||
}; | ||
|
||
final response = await http.post(Uri.parse(ApiModel.ApiUrl + '/lembretes'), | ||
headers: ApiModel.headers, body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<ResponseAPIModel> updateLembrete(LembreteModel model) async { | ||
var json = { | ||
"nome": model.nome, | ||
"data": model.data, | ||
"eAniversario": model.eAniversario, | ||
"cor": model.cor, | ||
}; | ||
|
||
final response = await http.put( | ||
Uri.parse(ApiModel.ApiUrl + '/lembretes/' + model.id.toString()), | ||
headers: ApiModel.headers, | ||
body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<ResponseAPIModel> excluirLembrete(LembreteModel model) async { | ||
final response = await http.delete( | ||
Uri.parse(ApiModel.ApiUrl + '/lembretes/' + model.id.toString()), | ||
headers: ApiModel.headers); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<List<LembreteModel>> getLembretes() async { | ||
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes'); | ||
|
||
var _url = Uri.parse(_uriSearchProduto.toString()); | ||
final response = await http.get(_url, headers: ApiModel.headers); | ||
|
||
Map<String, dynamic> jsonMap = jsonDecode(response.body); | ||
List<LembreteModel> listaLembretes = (jsonMap['lembretes'] as List) | ||
.map((item) => LembreteModel.fromJson(item)) | ||
.toList(); | ||
|
||
return listaLembretes; | ||
} | ||
|
||
Future<Map<String, dynamic>> get() async { | ||
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/lembretes'); | ||
|
||
var _url = Uri.parse(_uriSearchProduto.toString()); | ||
final response = await http.get(_url, headers: ApiModel.headers); | ||
|
||
Map<String, dynamic> jsonMap = jsonDecode(response.body); | ||
|
||
return jsonMap; | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
lib/components/dialogs/lembretes/lembreteCadastroDialog.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:organizei/Model/Lembrete/LembreteModel.dart'; | ||
import 'package:organizei/Repository/LembreteRepository.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/LembreteController.dart'; | ||
|
||
Future<dynamic> criarLembrete(BuildContext context, | ||
{LembreteModel? lembrete = null, Function? fecharDialog = null}) { | ||
late LembreteController lembreteController; | ||
|
||
lembreteController = LembreteController(LembreteRepository(), context); | ||
|
||
late bool? eAniversario = false; | ||
|
||
if (lembrete != null) { | ||
lembreteController.controllerNome.text = lembrete.nome ?? ''; | ||
lembreteController.controllerDataehora.text = lembrete.data ?? ''; | ||
lembreteController.lembreteAniversario(lembrete.eAniversario); | ||
eAniversario = lembrete.eAniversario; | ||
lembreteController.lembreteCor(lembrete.cor); | ||
lembreteController.lembreteId(lembrete.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: lembreteController.formKey, | ||
child: Padding( | ||
padding: const EdgeInsets.only(top: 24.0), | ||
child: ConstrainedBox( | ||
constraints: BoxConstraints( | ||
minHeight: MediaQuery.of(context).size.height, | ||
), | ||
child: DialogPersonalizado( | ||
nome: 'Lembrete', | ||
child: <Widget>[ | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 16), | ||
child: input( | ||
onSaved: lembreteController.lembreteNome, | ||
textController: lembreteController.controllerNome, | ||
label: 'nome', | ||
), | ||
), | ||
SelectData( | ||
controller: lembreteController.controllerDataehora, | ||
onSaved: lembreteController.lembreteDataehora, | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
crossAxisAlignment: CrossAxisAlignment.end, | ||
children: [ | ||
Padding( | ||
padding: const EdgeInsets.only(bottom: 4.0), | ||
child: Checkbox( | ||
//tristate: true, | ||
activeColor: const Color(0xFF6385C3), | ||
side: const BorderSide( | ||
width: 2, color: Colors.black), | ||
value: eAniversario, | ||
onChanged: (bool? value) async { | ||
setState(() { | ||
eAniversario = value; | ||
}); | ||
|
||
lembreteController | ||
.lembreteAniversario(eAniversario); | ||
}, | ||
), | ||
), | ||
const Padding( | ||
padding: EdgeInsets.only(bottom: 16), | ||
child: Text('é aniversário?'), | ||
), | ||
], | ||
), | ||
SelectCor( | ||
cor: lembreteController.lembreteCor, | ||
corAtual: lembrete?.cor ?? ''), | ||
Botao( | ||
texto: 'Salvar', | ||
cor: const Color(0xFF6385C3), | ||
clicar: () async { | ||
bool succes = | ||
await lembreteController.saveLembrete(); | ||
|
||
if (succes == true) { | ||
var nav = Navigator.of(context); | ||
nav.pop(); | ||
|
||
if (lembrete?.id != null) { | ||
//nav.pop(); | ||
nav.pop(); | ||
} | ||
fecharDialog!(); | ||
} | ||
}, | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.