-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from UnBArqDsw2021-2/178-requisicao_home_produtor
Adicionando requisição a Home do Técnico
- Loading branch information
Showing
7 changed files
with
236 additions
and
59 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
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
104 changes: 104 additions & 0 deletions
104
lib/controllers/home_tecnico/home_tecnico_controller.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,104 @@ | ||
import 'package:caderneta_campo_digital/models/CulturaModel.dart'; | ||
import 'package:caderneta_campo_digital/models/PlantioModel.dart'; | ||
import 'package:caderneta_campo_digital/models/ProdutorModel.dart'; | ||
import 'package:caderneta_campo_digital/models/PropriedadeModel.dart'; | ||
import 'package:caderneta_campo_digital/models/TalhaoModel.dart'; | ||
import 'package:caderneta_campo_digital/models/TecnicoModel.dart'; | ||
import 'package:caderneta_campo_digital/services/home_tecnico/home_tecnico_service.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class HomeTecnicoController { | ||
HomeTecnicoService homeTecnicoService = HomeTecnicoService(); | ||
bool loading = false; | ||
List<Propriedade> estates = []; | ||
|
||
Future<bool> getEstates() async { | ||
Response response = await homeTecnicoService.getData(); | ||
loading = false; | ||
|
||
if (response.data == null) { | ||
return false; | ||
} | ||
|
||
setData(response.data); | ||
|
||
return true; | ||
} | ||
|
||
List<PlantioModel> getPlantios(array) { | ||
List<PlantioModel> plantios = []; | ||
|
||
for (dynamic plantio in array) { | ||
plantios.add( | ||
PlantioModel( | ||
plantio['idPlantio'], | ||
CulturaModel( | ||
plantio['cultura']['idCultura'], | ||
plantio['cultura']['nome'], | ||
), | ||
plantio['dataPlantio'], | ||
plantio['estado'], | ||
'', | ||
false, | ||
), | ||
); | ||
} | ||
|
||
return plantios; | ||
} | ||
|
||
List<TalhaoModel> getTalhoes(array) { | ||
List<TalhaoModel> talhoes = []; | ||
|
||
for (dynamic talhao in array) { | ||
talhoes.add( | ||
TalhaoModel( | ||
talhao['idTalhao'], | ||
talhao['idPropriedade'], | ||
talhao['numero'], | ||
getPlantios(talhao['plantio']), | ||
), | ||
); | ||
} | ||
|
||
return talhoes; | ||
} | ||
|
||
void setData(data) { | ||
estates = []; | ||
for (dynamic estate in data) { | ||
var produtor = estate['produtor']; | ||
TecnicoModel tecnico = estate['tecnico'] == null | ||
? TecnicoModel.nulo() | ||
: TecnicoModel( | ||
estate['tecnico']['usuario']['cpf'], | ||
estate['tecnico']['usuario']['dataNascimento'], | ||
estate['tecnico']['usuario']['telefone'], | ||
estate['tecnico']['usuario']['nome'], | ||
estate['tecnico']['crea'], | ||
estate['tecnico']['formacao'], | ||
); | ||
|
||
estates.add(Propriedade( | ||
estate['idPropriedade'], | ||
estate['cep'], | ||
estate['estado'], | ||
estate['cidade'], | ||
estate['bairro'], | ||
estate['complemento'], | ||
estate['numeroCasa'], | ||
estate['hectares'], | ||
estate['logradouro'], | ||
ProdutorModel( | ||
produtor['usuario']['cpf'], | ||
produtor['usuario']['dataNascimento'], | ||
produtor['usuario']['telefone'], | ||
produtor['usuario']['nome'], | ||
produtor['dap'], | ||
), | ||
tecnico, | ||
getTalhoes(estate['talhao']), | ||
)); | ||
} | ||
} | ||
} |
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
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,13 @@ | ||
import 'package:caderneta_campo_digital/services/dio.dart'; | ||
import 'package:dio/dio.dart'; | ||
|
||
class HomeTecnicoService { | ||
Future<Response> getData() async { | ||
|
||
Response getResponse; | ||
|
||
getResponse = await DioClient.dioClient.fetch('propriedade/'); | ||
|
||
return getResponse; | ||
} | ||
} |