-
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
8 changed files
with
288 additions
and
23 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,146 @@ | ||
import 'dart:ffi'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:organizei/Model/Item/ItemModel.dart'; | ||
import 'package:organizei/Model/Lista/ListaModel.dart'; | ||
import 'package:organizei/Controller/Base/Base.dart'; | ||
import 'package:organizei/Repository/ListaRepository.dart'; | ||
import 'package:organizei/services/persistencia/login.configuracoes.dart'; | ||
|
||
class ListaController extends Base { | ||
ListaController(this.repository, this.context); | ||
|
||
final BuildContext context; | ||
final ListaRepository repository; | ||
final formKey = GlobalKey<FormState>(); | ||
var model = ListaModel(); | ||
//var loginConfiguracoes = LoginConfiguracoes(); | ||
|
||
listaId(int? value) => model.id = value; | ||
listaNome(String? value) => model.nome = value.toString(); | ||
listaCor(String? value) => model.cor = value.toString(); | ||
listaItens(List<ItemModel?>? value) => model.itens = value; | ||
|
||
var controllerNome = TextEditingController(); | ||
var controllerCor = TextEditingController(); | ||
|
||
Future<bool> saveLista() async { | ||
if (!formKey.currentState!.validate()) { | ||
return false; | ||
} | ||
|
||
formKey.currentState!.save(); | ||
|
||
try { | ||
if (model.id == null) { | ||
return await repository.addLista(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.updateLista(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<ListaModel>?> getListas() async { | ||
return await repository.getListas(); | ||
} | ||
|
||
Future<bool> excluirLista() async { | ||
try { | ||
return await repository.excluirLista(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 was deleted.
Oops, something went wrong.
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,29 @@ | ||
import 'package:organizei/Model/API/ResponseAPIModel.dart'; | ||
|
||
class ItemModel { | ||
int? id; | ||
String? nome; | ||
bool? concluido; | ||
ResponseAPIModel? responseAPIModel; | ||
|
||
ItemModel({ | ||
this.id, | ||
this.nome, | ||
this.concluido, | ||
}); | ||
|
||
ItemModel.fromJson(Map<String, dynamic> json) { | ||
id = int.parse(json['id']); | ||
nome = json['nome']; | ||
concluido = json['concluido']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['id'] = id; | ||
data['nome'] = nome; | ||
data['concluido'] = concluido; | ||
|
||
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,34 @@ | ||
import 'package:organizei/Model/API/ResponseAPIModel.dart'; | ||
import 'package:organizei/Model/Item/ItemModel.dart'; | ||
|
||
class ListaModel { | ||
int? id; | ||
String? nome; | ||
String? cor; | ||
List<ItemModel?>? itens; | ||
ResponseAPIModel? responseAPIModel; | ||
|
||
ListaModel({ | ||
this.id, | ||
this.nome, | ||
this.cor, | ||
this.itens, | ||
}); | ||
|
||
ListaModel.fromJson(Map<String, dynamic> json) { | ||
id = int.parse(json['id']); | ||
nome = json['nome']; | ||
cor = json['cor']; | ||
itens = json['itens']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['id'] = id; | ||
data['nome'] = nome; | ||
data['cor'] = cor; | ||
data['itens'] = itens; | ||
|
||
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
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,23 @@ | ||
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/Item/ItemModel.dart'; | ||
|
||
class ItemRepository { | ||
Future<ResponseAPIModel> concluirItem(ItemModel model, bool concluido) async { | ||
var json = { | ||
"concluido": concluido, | ||
}; | ||
|
||
final response = await http.put( | ||
Uri.parse( | ||
ApiModel.ApiUrl + '/item/' + model.id.toString() + '/concluir'), | ||
headers: ApiModel.headers, | ||
body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
} |
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,53 @@ | ||
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/Lista/ListaModel.dart'; | ||
|
||
import '../Model/Item/ItemModel.dart'; | ||
|
||
class ListaRepository { | ||
Future<ResponseAPIModel> addLista(ListaModel model) async { | ||
var json = {"nome": model.nome, "cor": model.cor, "itens": model.itens}; | ||
|
||
final response = await http.post(Uri.parse(ApiModel.ApiUrl + '/listas'), | ||
headers: ApiModel.headers, body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<ResponseAPIModel> updateLista(ListaModel model) async { | ||
var json = {"nome": model.nome, "cor": model.cor, "itens": model.itens}; | ||
|
||
final response = await http.put( | ||
Uri.parse(ApiModel.ApiUrl + '/listas/' + model.id.toString()), | ||
headers: ApiModel.headers, | ||
body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<ResponseAPIModel> excluirLista(ListaModel model) async { | ||
final response = await http.delete( | ||
Uri.parse(ApiModel.ApiUrl + '/listas/' + model.id.toString()), | ||
headers: ApiModel.headers); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<List<ListaModel>> getListas() async { | ||
Uri _uriSearchProduto = Uri.parse(ApiModel.ApiUrl + '/listas'); | ||
|
||
var _url = Uri.parse(_uriSearchProduto.toString()); | ||
final response = await http.get(_url, headers: ApiModel.headers); | ||
|
||
Map<String, dynamic> jsonMap = jsonDecode(response.body); | ||
List<ListaModel> listaProdutos = (jsonMap['listas'] as List) | ||
.map((item) => ListaModel.fromJson(item)) | ||
.toList(); | ||
|
||
return listaProdutos; | ||
} | ||
} |