From 91d219e157da9d05006663eb0ec3ebe9169c9c06 Mon Sep 17 00:00:00 2001 From: Ivan Antunes Date: Tue, 13 Aug 2024 16:57:02 -0300 Subject: [PATCH] fix: Selector de dados (Motivo e Nivel) --- .../details_component_action.dart | 13 +- .../schedule_complete_visit_page_widget.dart | 126 +++++++----------- 2 files changed, 52 insertions(+), 87 deletions(-) diff --git a/lib/components/templates_components/details_component/details_component_action.dart b/lib/components/templates_components/details_component/details_component_action.dart index d3805086..fda1e116 100644 --- a/lib/components/templates_components/details_component/details_component_action.dart +++ b/lib/components/templates_components/details_component/details_component_action.dart @@ -19,9 +19,7 @@ Widget buildDetails( BuildContext context, Future Function(BuildContext, int, int, String, String)? changeStatusAction) { - log('test'); - log('visitaWrapItem: ${visitaWrapItem.toString()}'); - log('test'); + return VisitRequestTemplateComponentWidget( buttons: [ if (getStatus(visitaWrapItem['VAW_STATUS']) == @@ -116,11 +114,12 @@ Widget buildDetails( context, MaterialPageRoute( builder: (context) => ScheduleCompleteVisitPageWidget( - dropdownValue1: visitaWrapItem['MOT_DESCRICAO'], + dropdownValue1: visitaWrapItem['MOT_DESCRICAO'], dropdownValue2: visitaWrapItem['NAC_DESCRICAO'], visitorJsonList: [visitaWrapItem], visitorStrList: visitaWrapItem['VTE_DOCUMENTO'], - )), + ) + ), ); }, options: FFButtonOptions( @@ -142,8 +141,8 @@ Widget buildDetails( status.active) // SHARE ACTION FFButtonWidget( text: FFLocalizations.of(context).getVariableText( - ptText: 'Reagendar', - enText: 'Reschedule', + ptText: 'Compartilhar', + enText: 'Share', ), icon: const Icon(Icons.share), onPressed: () async { diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart index 05d0a656..807a21f1 100644 --- a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart +++ b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart @@ -64,10 +64,7 @@ class _ScheduleCompleteVisitPageWidgetState // On page load action. SchedulerBinding.instance.addPostFrameCallback((_) async { - if ((widget.visitorStrList != null && widget.visitorStrList != '') && - ((widget.visitorJsonList != null && - (widget.visitorJsonList)!.isNotEmpty) != - null)) { + if ((widget.visitorStrList != null && widget.visitorStrList != '') && ((widget.visitorJsonList != null && (widget.visitorJsonList)!.isNotEmpty) != null)) { _model.visitorJsonList = widget.visitorJsonList! .where((e) => widget.visitorStrList == @@ -85,12 +82,9 @@ class _ScheduleCompleteVisitPageWidgetState return; } - if ((widget.dropdownValue1 != null && widget.dropdownValue1 != '') && - (widget.dropdownValue2 != null && widget.dropdownValue2 != '')) { + if ((widget.dropdownValue1 != null && widget.dropdownValue1 != '') && (widget.dropdownValue2 != null && widget.dropdownValue2 != '')) { _model.dropDownValue1 = widget.dropdownValue1!; - log('_model.dropdownValue1: ${_model.dropDownValue1 ?? ''}'); _model.dropDownValue2 = widget.dropdownValue2!; - log('_model.dropdownValue2: ${_model.dropDownValue2 ?? ''}'); safeSetState(() {}); } else { return; @@ -135,7 +129,7 @@ class _ScheduleCompleteVisitPageWidgetState } } - void_scrollListener() { + void _scrollListener() { if (_visitHistoryController.position.pixels == _visitHistoryController.position.maxScrollExtent) { _loadMoreVisitHistory(); @@ -1103,55 +1097,30 @@ Widget scheduleVisit(BuildContext context, ), ); } - final dropDownGetDadosResponse = - snapshot.data!; - final reasonsJsonList = - PhpGroup.getDadosCall.reasonsJsonList( - dropDownGetDadosResponse.jsonBody, - ); - // Algoritmo de match // PODE MANDAR DE VASCO - if (_model.dropDownValue1 != null && - _model.dropDownValue1!.isNotEmpty) { - final matchedValue = - reasonsJsonList?.firstWhere( - (element) => - element.toString() == - _model.dropDownValue1, - orElse: () => null, - ); - if (matchedValue != null) { - WidgetsBinding.instance - .addPostFrameCallback((_) { - _model.dropDownValueController1 - ?.value = matchedValue.toString(); - }); + + final dropDownGetDadosResponse = snapshot.data!; + final reasonsJsonList = PhpGroup.getDadosCall.reasonsJsonList(dropDownGetDadosResponse.jsonBody); + + if (_model.dropDownValue1 != '' && _model.dropDownValue1 != null) { + String value = _model.dropDownValue1.toString() ?? ''; + + if (value.contains('{') && value.contains('}') && value.contains(':')) { + // log("Valor e um Objeto | Usuário Escolheu o Motivo ${_model.dropDownValue1}"); + } else { + // log("Valor e uma String | Usuário Escolheu o Motivo ${_model.dropDownValue1}"); + if (reasonsJsonList != null && reasonsJsonList.isNotEmpty) { + var item = reasonsJsonList.where((reason) => reason['MOT_DESCRICAO'].toString().contains(_model.dropDownValue1 ?? '')); + _model.dropDownValue1 = item.firstOrNull.toString() ?? ''; + } } } return FlutterFlowDropDown( - fillColor: FlutterFlowTheme.of(context) - .primaryBackground, - controller: - _model.dropDownValueController1 ??= - FormFieldController( - _model.dropDownValue1 ?? ''), - options: reasonsJsonList != null && - reasonsJsonList != [] - ? List.from( - PhpGroup.getDadosCall - .reasonsJsonList( - dropDownGetDadosResponse - .jsonBody, - )! - .map((e) => e.toString()) - .toList()) - : [], - optionLabels: PhpGroup.getDadosCall - .reasonsMotDescStrList( - dropDownGetDadosResponse.jsonBody, - ), - onChanged: (val) => safeSetState( - () => _model.dropDownValue1 = val), + fillColor: FlutterFlowTheme.of(context).primaryBackground, + controller: _model.dropDownValueController1 ??= FormFieldController(_model.dropDownValue1 ??= ''), + options: reasonsJsonList != null && reasonsJsonList != [] ? reasonsJsonList.map((e) => e.toString()).toList() : [], + optionLabels: PhpGroup.getDadosCall.reasonsMotDescStrList(dropDownGetDadosResponse.jsonBody), + onChanged: (val) => safeSetState(() => _model.dropDownValue1 = val), width: double.infinity, height: double.infinity, textStyle: FlutterFlowTheme.of(context) @@ -1253,30 +1222,29 @@ Widget scheduleVisit(BuildContext context, ), ); } - final dropDownGetDadosResponse = - snapshot.data!; - final lavelList = - PhpGroup.getDadosCall.levelJsonList( - dropDownGetDadosResponse.jsonBody, - ); + + final dropDownGetDadosResponse = snapshot.data!; + final lavelList = PhpGroup.getDadosCall.levelJsonList(dropDownGetDadosResponse.jsonBody); + + if (_model.dropDownValue2 != '' && _model.dropDownValue2 != null) { + String value = _model.dropDownValue2.toString() ?? ''; + + if (value.contains('{') && value.contains('}') && value.contains(':')) { + // log("Valor e um Objeto | Usuário Escolheu o Nivel ${_model.dropDownValue2}"); + } else { + // log("Valor e uma String | Usuário Escolheu o Nivel ${_model.dropDownValue2}"); + if (lavelList != null && lavelList.isNotEmpty) { + var item = lavelList.where((level) => level['NAC_DESCRICAO'].toString().contains(_model.dropDownValue2 ?? '')); + _model.dropDownValue2 = item.firstOrNull.toString() ?? ''; + } + } + } + return FlutterFlowDropDown( - controller: - _model.dropDownValueController2 ??= - FormFieldController( - _model.dropDownValue2 ??= '', - ), - options: - lavelList != null && lavelList != [] - ? List.from(lavelList! - .map((e) => e.toString()) - .toList()) - : [], - optionLabels: PhpGroup.getDadosCall - .levelNACDescricaoStrList( - dropDownGetDadosResponse.jsonBody, - ), - onChanged: (val) => safeSetState( - () => _model.dropDownValue2 = val), + controller: _model.dropDownValueController2 ??= FormFieldController(_model.dropDownValue2 ??= ''), + options: lavelList != null && lavelList != [] ? lavelList.map((e) => e.toString()).toList() : [], + optionLabels: PhpGroup.getDadosCall.levelNACDescricaoStrList(dropDownGetDadosResponse.jsonBody), + onChanged: (val) => safeSetState(() => _model.dropDownValue2 = val), width: double.infinity, height: double.infinity, textStyle: FlutterFlowTheme.of(context) @@ -1323,7 +1291,7 @@ Widget scheduleVisit(BuildContext context, ), ], ), - if (_model.dropDownValue1 == '') + if (_model.dropDownValue2 == '') Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.start, @@ -1584,7 +1552,6 @@ Widget scheduleVisit(BuildContext context, ), onPressed: _model.isValid() ? () async { - log(_model.dropDownValue1.toString()); await showDialog( context: context, @@ -1607,7 +1574,6 @@ Widget scheduleVisit(BuildContext context, ), icon: const Icon(Icons.done), onPressed: () async { - log('visitorStrList ${_model.visitorStrList}'); showAlertDialog( context, FFLocalizations.of(context)