-
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
15 changed files
with
732 additions
and
20 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,167 @@ | ||
import 'dart:ffi'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:organizei/Model/Atividade/AtividadeModel.dart'; | ||
import 'package:organizei/Controller/Base/Base.dart'; | ||
import 'package:organizei/Repository/AtividadeRepository.dart'; | ||
import 'package:organizei/services/persistencia/login.configuracoes.dart'; | ||
|
||
class AtividadeController extends Base { | ||
AtividadeController(this.repository, this.context); | ||
|
||
final BuildContext context; | ||
final AtividadeRepository repository; | ||
final formKey = GlobalKey<FormState>(); | ||
var model = AtividadeModel(); | ||
//var loginConfiguracoes = LoginConfiguracoes(); | ||
|
||
atividadeId(int? value) => model.id = value; | ||
atividadeNome(String? value) => model.nome = value.toString(); | ||
atividadeDataInical(String? value) => model.dataInicial = value.toString(); | ||
atividadeObservacao(String? value) => model.observacao = value.toString(); | ||
atividadeDataFinal(String? value) => model.dataFinal = value.toString(); | ||
atividadeCor(String? value) => model.cor = value.toString(); | ||
atividadePrioridade(String? value) => model.prioridade = value.toString(); | ||
|
||
var controllerNome = TextEditingController(); | ||
var controllerObservacao = TextEditingController(); | ||
var controllerPrioridade = TextEditingController(); | ||
var controllerCor = TextEditingController(); | ||
var controllerDataIncial = TextEditingController(); | ||
var controllerDataFinal = TextEditingController(); | ||
|
||
Future<bool> saveAtividade(Function? addAtividade) async { | ||
if (!formKey.currentState!.validate()) { | ||
return false; | ||
} | ||
|
||
formKey.currentState!.save(); | ||
|
||
if (addAtividade != null) { | ||
addAtividade(model); | ||
} | ||
|
||
try { | ||
if (model.id != null) { | ||
return await repository.updateAtividade(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 true; | ||
} | ||
} catch (e) { | ||
print(e); | ||
return false; | ||
} | ||
} | ||
|
||
Future<Map<String, dynamic>> getAtividades() async { | ||
return await repository.getAtividades(); | ||
} | ||
|
||
Future<bool> concluirAtividade(bool concluido) async { | ||
try { | ||
return await repository | ||
.concluirAtividade(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; | ||
} | ||
} | ||
|
||
Future<bool> excluirAtividade() async { | ||
try { | ||
return await repository.excluirAtividade(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
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,50 @@ | ||
import 'package:organizei/Model/API/ResponseAPIModel.dart'; | ||
|
||
class AtividadeModel { | ||
int? id; | ||
int? idProjeto; | ||
String? nome; | ||
String? dataInicial; | ||
String? observacao; | ||
String? dataFinal; | ||
String? cor; | ||
String? prioridade; | ||
bool? concluido; | ||
ResponseAPIModel? responseAPIModel; | ||
|
||
AtividadeModel({ | ||
this.id, | ||
this.nome, | ||
this.dataInicial, | ||
this.observacao, | ||
this.dataFinal, | ||
this.cor, | ||
this.prioridade, | ||
this.concluido, | ||
}); | ||
|
||
AtividadeModel.fromJson(Map<String, dynamic> json) { | ||
id = int.parse(json['id']); | ||
nome = json['nome']; | ||
dataInicial = json['dataInicial']; | ||
observacao = json['observacao']; | ||
dataFinal = json['dataFinal']; | ||
cor = json['cor']; | ||
prioridade = json['prioridade']; | ||
concluido = json['concluido']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = new Map<String, dynamic>(); | ||
data['id'] = id; | ||
data['nome'] = nome; | ||
data['dataInicial'] = dataInicial; | ||
data['observacao'] = observacao; | ||
data['dataFinal'] = dataFinal; | ||
data['cor'] = cor; | ||
data['prioridade'] = prioridade; | ||
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
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,90 @@ | ||
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/Atividade/AtividadeModel.dart'; | ||
|
||
class AtividadeRepository { | ||
Future<ResponseAPIModel> addAtividade(AtividadeModel model) async { | ||
var json = { | ||
"nome": model.nome, | ||
"dataInicial": model.dataInicial, | ||
"observacao": model.observacao, | ||
"dataFinal": model.dataFinal, | ||
"cor": model.cor, | ||
"prioridade": model.prioridade, | ||
}; | ||
|
||
final response = await http.post(Uri.parse(ApiModel.ApiUrl + '/atividades'), | ||
headers: ApiModel.headers, body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<ResponseAPIModel> updateAtividade(AtividadeModel model) async { | ||
var json = { | ||
"nome": model.nome, | ||
"dataInicial": model.dataInicial, | ||
"observacao": model.observacao, | ||
"dataFinal": model.dataFinal, | ||
"cor": model.cor, | ||
"prioridade": model.prioridade, | ||
}; | ||
|
||
final response = await http.put( | ||
Uri.parse(ApiModel.ApiUrl + '/atividades/' + model.id.toString()), | ||
headers: ApiModel.headers, | ||
body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<ResponseAPIModel> concluirAtividade( | ||
AtividadeModel model, bool concluido) async { | ||
var json = { | ||
"concluido": concluido, | ||
}; | ||
|
||
final response = await http.put( | ||
Uri.parse(ApiModel.ApiUrl + | ||
'/atividades/' + | ||
model.id.toString() + | ||
'/concluir'), | ||
headers: ApiModel.headers, | ||
body: jsonEncode(json)); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<ResponseAPIModel> excluirAtividade(AtividadeModel model) async { | ||
final response = await http.delete( | ||
Uri.parse(ApiModel.ApiUrl + '/atividades/' + model.id.toString()), | ||
headers: ApiModel.headers); | ||
|
||
return ResponseAPIModel.fromJson(jsonDecode(response.body)); | ||
} | ||
|
||
Future<Map<String, dynamic>> getAtividades() async { | ||
Uri url = Uri.parse(ApiModel.ApiUrl + '/atividades'); | ||
|
||
var _url = Uri.parse(url.toString()); | ||
final response = await http.get(_url, headers: ApiModel.headers); | ||
|
||
Map<String, dynamic> jsonMap = jsonDecode(response.body); | ||
|
||
return jsonMap; | ||
} | ||
|
||
Future<Map<String, dynamic>> get() async { | ||
Uri url = Uri.parse(ApiModel.ApiUrl + '/atividades'); | ||
|
||
var _url = Uri.parse(url.toString()); | ||
final response = await http.get(_url, headers: ApiModel.headers); | ||
|
||
Map<String, dynamic> jsonMap = jsonDecode(response.body); | ||
|
||
return jsonMap; | ||
} | ||
} |
Oops, something went wrong.