Skip to content

Commit

Permalink
Merge pull request #16 from UnBArqDsw2021-2/178-requisicao_home_produtor
Browse files Browse the repository at this point in the history
Adicionando requisição a Home do Técnico
  • Loading branch information
brenno-silva authored Apr 13, 2022
2 parents baffc8f + c3f2a8f commit 98b6182
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 59 deletions.
8 changes: 6 additions & 2 deletions lib/components/estate_card.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:caderneta_campo_digital/global/global.dart';
import 'package:caderneta_campo_digital/models/PropriedadeModel.dart';
import 'package:caderneta_campo_digital/pages/estate/estate_page.dart';
import 'package:caderneta_campo_digital/utils/utils.dart';
Expand All @@ -16,7 +17,7 @@ class EstateCard extends StatelessWidget {
}

String getQtdTalhoes() {
return 'Número de talhões: '+ estate.talhoes.length.toString();
return 'Número de talhões: ' + estate.talhoes.length.toString();
}

@override
Expand All @@ -39,7 +40,10 @@ class EstateCard extends StatelessWidget {
context,
MaterialPageRoute(
builder: (BuildContext context) {
return EstatePage(estate: estate);
return EstatePage(
estate: estate,
isProductorTheViewer: SharedInfo.actualUser.isProductor,
);
},
),
);
Expand Down
28 changes: 26 additions & 2 deletions lib/components/topbar_arrow_back.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:caderneta_campo_digital/global/global.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

Expand Down Expand Up @@ -80,7 +81,7 @@ class TopbarArrowBack extends StatelessWidget implements PreferredSizeWidget {
bottomRight: Radius.circular(20),
),
),
actions: hasActions
actions: hasActions && SharedInfo.actualUser.isProductor
? [
Padding(
padding: const EdgeInsets.only(right: 10),
Expand Down Expand Up @@ -128,7 +129,30 @@ class TopbarArrowBack extends StatelessWidget implements PreferredSizeWidget {
),
),
]
: [],
: hasActions
? [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: SizedBox(
width: size.width * 0.1,
height: size.height * 0.09,
child: MaterialButton(
padding: EdgeInsets.symmetric(horizontal: 5),
onPressed: () {
if (onPressedHistoric != null) {
onPressedHistoric!();
}
},
highlightColor: Colors.transparent,
child: Icon(
Icons.history_edu,
color: Color(0xFFFFFFFF),
),
),
),
),
]
: [],
);
}
}
104 changes: 104 additions & 0 deletions lib/controllers/home_tecnico/home_tecnico_controller.dart
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']),
));
}
}
}
18 changes: 12 additions & 6 deletions lib/models/PropriedadeModel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,30 @@ class Propriedade {
this.talhoes,
);

Tuple2<List<TalhaoModel>, List<TalhaoModel>> getPlotsActive({required List<TalhaoModel> plots}) {
Tuple2<List<TalhaoModel>, List<TalhaoModel>> getPlots({
bool isProductorTheViewer = false,
}) {
List<TalhaoModel> activePlots = [];
List<TalhaoModel> nonActivePlots = [];
bool isActive = false;

for (TalhaoModel plot in plots) {
for (TalhaoModel plot in talhoes) {
isActive = false;
for (PlantioModel plantation in plot.plantios) {
if(plantation.estado == "Plantado") {
plot.setButtonsToNotEmptyTalhao();
if (plantation.estado == "Plantado") {
if (isProductorTheViewer) {
plot.setButtonsToNotEmptyTalhao();
}
activePlots.add(plot);
isActive = true;
break;
}
}

if(!isActive) {
plot.setButtonsToEmptyTalhao();
if (!isActive) {
if (isProductorTheViewer) {
plot.setButtonsToEmptyTalhao();
}
nonActivePlots.add(plot);
}
}
Expand Down
59 changes: 32 additions & 27 deletions lib/pages/estate/estate_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,57 @@ import 'package:tuple/tuple.dart';

class EstatePage extends StatefulWidget {
final Propriedade estate;
const EstatePage({Key? key, required this.estate}) : super(key: key);
final bool isProductorTheViewer;
const EstatePage({
Key? key,
required this.estate,
required this.isProductorTheViewer,
}) : super(key: key);

@override
State<EstatePage> createState() => _EstatePageState();
}

class _EstatePageState extends State<EstatePage> {

@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;

Tuple2 plots = widget.estate.getPlotsActive(plots: widget.estate.talhoes);
Tuple2 plots = widget.estate.getPlots(isProductorTheViewer: widget.isProductorTheViewer);

return Scaffold(
appBar: TopbarArrowBack(
topbarHeight: size * 0.11,
hasActions: true,
title: widget.estate.complemento,
),
body: widget.estate.talhoes.isNotEmpty ? SingleChildScrollView(
child: Column(
children: [
PlotsList(
plots: plots.item1,
title: 'Ativos',
),
Container(
margin: EdgeInsets.only(
top: 10,
bottom: 10,
body: widget.estate.talhoes.isNotEmpty
? SingleChildScrollView(
child: Column(
children: [
PlotsList(
plots: plots.item1,
title: 'Ativos',
),
Container(
margin: EdgeInsets.only(
top: 10,
bottom: 10,
),
width: size.width,
height: 1,
color: Color(0xFF000000),
),
PlotsList(
plots: plots.item2,
title: 'Inativos',
),
],
),
width: size.width,
height: 1,
color: Color(0xFF000000),
)
: Center(
child: Text('Não existem talhões', style: Utils.estateTextStyle),
),
PlotsList(
plots: plots.item2,
title: 'Inativos',
),
],
),
)
: Center(
child: Text('Não existem talhões', style: Utils.estateTextStyle),
),
);
}
}
65 changes: 43 additions & 22 deletions lib/pages/home_tecnico/home_tecnico.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import 'package:caderneta_campo_digital/components/estate_card.dart';
import 'package:caderneta_campo_digital/components/loading.dart';
import 'package:caderneta_campo_digital/components/topbar.dart';
import 'package:caderneta_campo_digital/controllers/home_tecnico/home_tecnico_controller.dart';
import 'package:caderneta_campo_digital/pages/home_tecnico/components/pendency_card.dart';
import 'package:caderneta_campo_digital/utils/utils.dart';
import 'package:flutter/material.dart';

class HomeTecnicoPage extends StatelessWidget {


class HomeTecnicoPage extends StatefulWidget {
const HomeTecnicoPage({Key? key}) : super(key: key);

@override
State<HomeTecnicoPage> createState() => _HomeTecnicoPageState();
}

class _HomeTecnicoPageState extends State<HomeTecnicoPage> {
HomeTecnicoController homeTecnicoController = HomeTecnicoController();

@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
Expand All @@ -12,28 +26,35 @@ class HomeTecnicoPage extends StatelessWidget {
appBar: Topbar(topbarHeight: (size * 0.14)),
body: SingleChildScrollView(
child: Column(
children: const <Widget>[
children: <Widget>[
PendencyCard(),
// EstateCard(
// estateName: "Propriedade 1",
// estateAddress: "ENDERECO",
// qtdPlot: 5,
// ),
// EstateCard(
// estateName: "Propriedade 1",
// estateAddress: "ENDERECO",
// qtdPlot: 5,
// ),
// EstateCard(
// estateName: "Propriedade 1",
// estateAddress: "ENDERECO",
// qtdPlot: 5,
// ),
// EstateCard(
// estateName: "Propriedade 1",
// estateAddress: "ENDERECO",
// qtdPlot: 5,
// ),
Container(
padding: EdgeInsets.symmetric(vertical: 4),
height: size.height * 0.64,
child: FutureBuilder(
future: homeTecnicoController.getEstates(),
builder: (context, snapshot) {
return snapshot.connectionState == ConnectionState.done
? snapshot.data == true
? ListView.builder(
padding: const EdgeInsets.all(8),
itemCount: homeTecnicoController.estates.length,
itemBuilder: (context, index) {
return EstateCard(
estate: homeTecnicoController.estates[index],
);
},
)
: Center(
child: Text(
'Não existem propriedades',
style: Utils.estateTextStyle,
),
)
: Loading();
},
),
),
],
),
),
Expand Down
13 changes: 13 additions & 0 deletions lib/services/home_tecnico/home_tecnico_service.dart
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;
}
}

0 comments on commit 98b6182

Please sign in to comment.