From d2cf5b425226c806da2c19b24763ab665b819456 Mon Sep 17 00:00:00 2001 From: jantunesmesias Date: Tue, 13 Aug 2024 09:03:14 -0300 Subject: [PATCH 1/5] fix: Fix setState calls in message history page widget --- .../pushNotificationService.dart | 98 ++------ .../details_component_action.dart | 49 +++- ...earch_modal_template_component_widget.dart | 31 ++- .../liberation_history_widget.dart | 228 +++--------------- .../message_history_page_widget.dart | 104 ++++---- 5 files changed, 170 insertions(+), 340 deletions(-) diff --git a/lib/backend/push_notification/pushNotificationService.dart b/lib/backend/push_notification/pushNotificationService.dart index 09751698..537e780a 100644 --- a/lib/backend/push_notification/pushNotificationService.dart +++ b/lib/backend/push_notification/pushNotificationService.dart @@ -491,85 +491,25 @@ class NotificationHandler { FlutterFlowIconButton( icon: const Icon(Icons.close), onPressed: () async { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - FFLocalizations.of(context).getVariableText( - ptText: 'Bloquear Visita', - enText: 'Block Visit', - ), - ), - content: Text( - FFLocalizations.of(context).getVariableText( - ptText: - 'Você tem certeza que deseja bloquear essa visita?', - enText: - 'Are you sure you want to block this visit?', - ), - ), - backgroundColor: - FlutterFlowTheme.of(context).primaryBackground, - actions: [ - FFButtonWidget( - text: FFLocalizations.of(context).getVariableText( - enText: 'No', - ptText: 'Não', - ), - onPressed: () { - Navigator.pop(context); - }, - options: FFButtonOptions( - width: 100, - height: 40, - color: FlutterFlowTheme.of(context) - .primaryBackground, - textStyle: TextStyle( - color: FlutterFlowTheme.of(context) - .primaryText, - ), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, - width: 1, - ), - borderRadius: BorderRadius.circular(10)), - ), - FFButtonWidget( - text: FFLocalizations.of(context).getVariableText( - enText: 'Yes', - ptText: 'Sim', - ), - onPressed: () async { - await answersRequest.call( - context, - message['referencia'].toString(), - 'B', - 'Mensagem', - message['idVisitante'].toString(), - ); - }, - options: FFButtonOptions( - width: 100, - height: 40, - color: FlutterFlowTheme.of(context) - .primaryBackground, - textStyle: TextStyle( - color: - FlutterFlowTheme.of(context).primaryText, - ), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, - width: 1, - ), - borderRadius: BorderRadius.circular(10), - ), - ), - ], - ); - }); + showAlertDialog( + context, + FFLocalizations.of(context).getVariableText( + ptText: 'Bloquear Visita', + enText: 'Block Visit', + ), + FFLocalizations.of(context).getVariableText( + ptText: + 'Você tem certeza que deseja bloquear essa visita?', + enText: 'Are you sure you want to block this visit?', + ), () async { + await answersRequest.call( + context, + message['referencia'].toString(), + 'B', + 'Mensagem', + message['idVisitante'].toString(), + ); + }); }, ), ], 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 3e3b07d7..21e7808a 100644 --- a/lib/components/templates_components/details_component/details_component_action.dart +++ b/lib/components/templates_components/details_component/details_component_action.dart @@ -1,4 +1,4 @@ -import 'dart:math'; +import 'dart:developer'; import 'package:flutter/material.dart'; import 'package:hub/actions/actions.dart'; @@ -18,11 +18,16 @@ Widget buildDetails( BuildContext context, Future Function(BuildContext, int, int, String, String)? changeStatusAction) { + log('visitaWrapItem: ${visitaWrapItem.toString()}'); return VisitRequestTemplateComponentWidget( buttons: [ if (getStatus(visitaWrapItem['VAW_STATUS']) == status.active) // REJECT ACTION - FlutterFlowIconButton( + FFButtonWidget( + text: FFLocalizations.of(context).getVariableText( + ptText: 'Cancelar', + enText: 'Cancel', + ), icon: const Icon(Icons.close), onPressed: () async { showAlertDialog( @@ -77,6 +82,20 @@ Widget buildDetails( }); }); }, + options: FFButtonOptions( + width: 130, + height: 40, + color: FlutterFlowTheme.of(context).primaryBackground, + elevation: 0, + textStyle: TextStyle( + color: FlutterFlowTheme.of(context).primaryText, + ), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).primaryBackground, + width: 1, + ), + // borderRadius: 12, + ), ), if (getStatus(visitaWrapItem['VAW_STATUS']) != status.active) // RECALL ACTION @@ -89,9 +108,15 @@ Widget buildDetails( onPressed: () async { Navigator.pop(context); Navigator.pop(context); + context.pushNamed( 'scheduleCompleteVisitPage', queryParameters: { + 'dropdownValue1': visitaWrapItem['MOT_DESCRICAO'], + 'dropdownValue2': serializeParam( + visitaWrapItem['NAC_DESCRICAO'], + ParamType.String, + ), 'visitorStrList': serializeParam( visitaWrapItem['VTE_DOCUMENTO'], ParamType.String, @@ -121,7 +146,11 @@ Widget buildDetails( ), if (getStatus(visitaWrapItem['VAW_STATUS']) == status.active) // SHARE ACTION - FlutterFlowIconButton( + FFButtonWidget( + text: FFLocalizations.of(context).getVariableText( + ptText: 'Reagendar', + enText: 'Reschedule', + ), icon: const Icon(Icons.share), onPressed: () async { Share.share(''' @@ -134,6 +163,20 @@ Olá, \*${visitaWrapItem['VTE_NOME']}\*! Você foi convidado para \*${visitaWrap URL do Convite: https://visita.freaccess.com.br/${visitaWrapItem['VAW_ID']}/${visitaWrapItem['CLI_ID']}/${visitaWrapItem['VAW_CHAVE']} '''); }, + options: FFButtonOptions( + width: 130, + height: 40, + color: FlutterFlowTheme.of(context).primaryBackground, + elevation: 0, + textStyle: TextStyle( + color: FlutterFlowTheme.of(context).primaryText, + ), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context).primaryBackground, + width: 1, + ), + // borderRadius: 12, + ), ), ], labelsHashMap: Map.from({ diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart index 0239cf0b..b545ed9f 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart @@ -37,7 +37,7 @@ class _VisitorSearchModalTemplateComponentWidgetState late VisitorSearchModalTemplateComponentModel _model; @override - void setState(VoidCallback callback) { + safeSetState(VoidCallback callback) { super.setState(callback); _model.onUpdate(); } @@ -88,7 +88,7 @@ class _VisitorSearchModalTemplateComponentWidgetState focusNode: _model.textFieldFocusNode, onFieldSubmitted: (_) async { await addVisitor(context); - setState(() {}); + safeSetState(() {}); }, autofocus: false, textInputAction: TextInputAction.done, @@ -267,7 +267,7 @@ class _VisitorSearchModalTemplateComponentWidgetState // ), // ); // }, - // ).then((value) => safeSetState(() {})); + // ).then((value) => safeSetState(() {})); }, child: Container( width: 100.0, @@ -356,7 +356,7 @@ class _VisitorSearchModalTemplateComponentWidgetState onPressed: () async { _model.removeFromVisitors( visitorItem); - setState(() {}); + safeSetState(() {}); }, ), ], @@ -391,7 +391,7 @@ class _VisitorSearchModalTemplateComponentWidgetState ? () async { await addVisitor(context); - setState(() {}); + safeSetState(() {}); } : () async { await sendVisitors(context); @@ -437,7 +437,7 @@ class _VisitorSearchModalTemplateComponentWidgetState ], ), const SizedBox( - height: 10.0, + height: 20.0, ) ], ), @@ -456,7 +456,7 @@ class _VisitorSearchModalTemplateComponentWidgetState } Future addVisitor(BuildContext context) async { - setState(() { + safeSetState(() { _model.textController?.text = _model.textController.text; _model.textController?.selection = TextSelection.collapsed(offset: _model.textController!.text.length); @@ -470,15 +470,22 @@ class _VisitorSearchModalTemplateComponentWidgetState ); if (PhpGroup.getVisitorByDocCall.vistanteId( - (_model.getVisitorByDoc?.jsonBody ?? ''), - ) != - '0') { + (_model.getVisitorByDoc?.jsonBody ?? ''), + ) != + '0' && + PhpGroup.getVisitorByDocCall + .error((_model.getVisitorByDoc?.jsonBody ?? '')) == + false && + PhpGroup.getVisitorByDocCall + .vistanteId((_model.getVisitorByDoc?.jsonBody ?? '')) != + null) { + log('visitor found: ${PhpGroup.getVisitorByDocCall.vistanteId((_model.getVisitorByDoc?.jsonBody ?? ''))}'); _model.addToVisitors(PhpGroup.getVisitorByDocCall.visitante( (_model.getVisitorByDoc?.jsonBody ?? ''), )); - setState(() {}); + safeSetState(() {}); _model.addToDocs(_model.textController.text); - setState(() {}); + safeSetState(() {}); } else { await showAdaptiveDialog( useSafeArea: true, diff --git a/lib/pages/liberation_history/liberation_history_widget.dart b/lib/pages/liberation_history/liberation_history_widget.dart index 9ad1dfcf..7389a2c8 100644 --- a/lib/pages/liberation_history/liberation_history_widget.dart +++ b/lib/pages/liberation_history/liberation_history_widget.dart @@ -53,7 +53,7 @@ class _LiberationHistoryWidgetState extends State { void onUpdate(BuildContext context) { _model.clearGetLiberationsCache(); - setState(() {}); + safeSetState(() {}); } @override @@ -338,20 +338,6 @@ Widget liberationHistoryItemCard( return Dialog( alignment: Alignment.center, child: VisitRequestTemplateComponentWidget( - // vteName: liberationHistoryItem['VTE_NOME'], - // vteReason: liberationHistoryItem['NOT_MOTIVO'], - // vawDate: liberationHistoryItem['NOT_STATUS'] == 'S' - // ? liberationHistoryItem['NOT_DTENVIO'] - // : liberationHistoryItem['NOT_DTRESPOSTA'], - // vawStatus: liberationHistoryItem['NOT_STATUS'], - // vteMsg: liberationHistoryItem['NOT_MSGENVIO'], - // vteUUID: liberationHistoryItem['VTE_ID'], - // cliUUID: FFAppState().cliUUID, - // msgUUID: liberationHistoryItem['NOT_ID'], - // vawDestino: liberationHistoryItem['NOT_DESTINO'], - // vawUUID: liberationHistoryItem['NOT_ID'], - // vawName: liberationHistoryItem['NOT_NOME'], - // vawRef: liberationHistoryItem['NOT_ID'], labelsHashMap: Map.from({ 'Nome:': liberationHistoryItem['VTE_NOME'], 'Data:': liberationHistoryItem['NOT_DTENVIO'], @@ -364,182 +350,32 @@ Widget liberationHistoryItemCard( FlutterFlowIconButton( icon: const Icon(Icons.done), onPressed: () async { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - FFLocalizations.of(context).getVariableText( - ptText: 'Aprovar Visita', - enText: 'Approve Visit', - ), - ), - content: Text( - FFLocalizations.of(context).getVariableText( - ptText: - 'Você tem certeza que deseja aprovar essa visita?', - enText: - 'Are you sure you want to approve this visit?', - ), - ), - backgroundColor: FlutterFlowTheme.of(context) - .primaryBackground, - actions: [ - FFButtonWidget( - text: FFLocalizations.of(context) - .getVariableText( - enText: 'No', - ptText: 'Não', - ), - onPressed: () { - Navigator.pop(context); - }, - options: FFButtonOptions( - width: 100, - height: 40, - color: FlutterFlowTheme.of(context) - .primaryBackground, - textStyle: TextStyle( - color: FlutterFlowTheme.of(context) - .primaryText, - ), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, - width: 1, - ), - borderRadius: BorderRadius.circular(10)), - ), - FFButtonWidget( - text: FFLocalizations.of(context) - .getVariableText( - enText: 'Yes', - ptText: 'Sim', - ), - onPressed: () async { - Navigator.pop(context); - Navigator.pop(context); - await answersRequest - .call( - context, - liberationHistoryItem['NOT_ID'] - .toString(), - 'L', - 'Mensagem', - liberationHistoryItem['VTE_ID'] - .toString(), - ) - .then((value) {}); - }, - options: FFButtonOptions( - width: 100, - height: 40, - color: FlutterFlowTheme.of(context) - .primaryBackground, - textStyle: TextStyle( - color: FlutterFlowTheme.of(context) - .primaryText, - ), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, - width: 1, - ), - borderRadius: BorderRadius.circular(10), - ), - ), - ], - ); - }); - }, - ), - if (liberationHistoryItem['NOT_STATUS'] == 'S') - FlutterFlowIconButton( - icon: const Icon(Icons.close), - onPressed: () async { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: Text( - FFLocalizations.of(context).getVariableText( - ptText: 'Bloquear Visita', - enText: 'Block Visit', - ), - ), - content: Text( - FFLocalizations.of(context).getVariableText( - ptText: - 'Você tem certeza que deseja bloquear essa visita?', - enText: - 'Are you sure you want to block this visit?', - ), - ), - backgroundColor: FlutterFlowTheme.of(context) - .primaryBackground, - actions: [ - FFButtonWidget( - text: FFLocalizations.of(context) - .getVariableText( - enText: 'No', - ptText: 'Não', - ), - onPressed: () { - Navigator.pop(context); - }, - options: FFButtonOptions( - width: 100, - height: 40, - color: FlutterFlowTheme.of(context) - .primaryBackground, - textStyle: TextStyle( - color: FlutterFlowTheme.of(context) - .primaryText, - ), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, - width: 1, - ), - borderRadius: BorderRadius.circular(10)), - ), - FFButtonWidget( - text: FFLocalizations.of(context) - .getVariableText( - enText: 'Yes', - ptText: 'Sim', - ), - onPressed: () async { - await answersRequest.call( - context, - liberationHistoryItem['NOT_ID'] - .toString(), - 'B', - 'Mensagem', - liberationHistoryItem['VTE_ID'] - .toString(), - ); - }, - options: FFButtonOptions( - width: 100, - height: 40, - color: FlutterFlowTheme.of(context) - .primaryBackground, - textStyle: TextStyle( - color: FlutterFlowTheme.of(context) - .primaryText, - ), - borderSide: BorderSide( - color: FlutterFlowTheme.of(context) - .primaryBackground, - width: 1, - ), - borderRadius: BorderRadius.circular(10), - ), - ), - ], - ); - }); + Navigator.pop(context); + await answersRequest + .call( + context, + liberationHistoryItem['NOT_ID'].toString(), + 'L', + 'Mensagem', + liberationHistoryItem['VTE_ID'].toString(), + ) + .then((value) { + if (value) { + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Successfully resolved visit', + ptText: 'Visita resolvida com sucesso'), + false); + } else { + return showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Error resolving visit', + ptText: 'Erro ao resolver visita'), + true); + } + }); }, ), ], @@ -567,9 +403,6 @@ Widget liberationHistoryItemCard( ], imagePath: 'https://freaccess.com.br/freaccess/getImage.php?cliID=${FFAppState().cliUUID}&atividade=getFoto&Documento=${liberationHistoryItem['VTE_ID'] ?? ''}&tipo=E', - - // changeStatusAction: answersRequest, - // vteDocument: liberationHistoryItem['VTE_DOCUMENTO'], ), ); }, @@ -580,7 +413,12 @@ Widget liberationHistoryItemCard( _pushNotificationService.onMessageReceived.listen((received) { if (received.data['click_action'] == 'cancel_request') { _pushNotificationService.dispose(); - snackbar(context, opt: true); + showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Successfully resolved visit', + ptText: 'Visita resolvida com sucesso'), + false); context.pushReplacementNamed( 'liberationHistory', extra: { diff --git a/lib/pages/message_history_page/message_history_page_widget.dart b/lib/pages/message_history_page/message_history_page_widget.dart index 6a4798b2..6bcc97b4 100644 --- a/lib/pages/message_history_page/message_history_page_widget.dart +++ b/lib/pages/message_history_page/message_history_page_widget.dart @@ -20,10 +20,12 @@ class MessageHistoryPageWidget extends StatefulWidget { const MessageHistoryPageWidget({super.key}); @override - State createState() => _MessageHistoryPageWidgetState(); + State createState() => + _MessageHistoryPageWidgetState(); } -class _MessageHistoryPageWidgetState extends State with TickerProviderStateMixin { +class _MessageHistoryPageWidgetState extends State + with TickerProviderStateMixin { late MessageHistoryPageModel _model; final scaffoldKey = GlobalKey(); @@ -47,25 +49,29 @@ class _MessageHistoryPageWidgetState extends State wit _messageFuture = fetchMessage(); - _scrollController = ScrollController()..addListener(() { - if (_scrollController.position.atEdge && _scrollController.position.pixels != 0) { - _loadMore(); - } - }); + _scrollController = ScrollController() + ..addListener(() { + if (_scrollController.position.atEdge && + _scrollController.position.pixels != 0) { + _loadMore(); + } + }); - _model.tabBarController = TabController(vsync: this, length: 3, initialIndex: 0)..addListener(() { - if (_model.tabBarController?.index == 0) { - _destinyType = "P"; - } else if (_model.tabBarController?.index == 1) { - _destinyType = "A"; - } else { - _destinyType = "T"; - } + _model.tabBarController = + TabController(vsync: this, length: 3, initialIndex: 0) + ..addListener(() { + if (_model.tabBarController?.index == 0) { + _destinyType = "P"; + } else if (_model.tabBarController?.index == 1) { + _destinyType = "A"; + } else { + _destinyType = "T"; + } - _pageNumber = 1; - _messageWrap = []; - _messageFuture = fetchMessage(); - }); + _pageNumber = 1; + _messageWrap = []; + _messageFuture = fetchMessage(); + }); _model.textController ??= TextEditingController(); _model.textFieldFocusNode ??= FocusNode(); @@ -80,7 +86,7 @@ class _MessageHistoryPageWidgetState extends State wit void onUpdate(BuildContext context) { _model.clearGetLiberationsCache(); - setState(() {}); + safeSetState(() {}); } @override @@ -129,7 +135,8 @@ class _MessageHistoryPageWidgetState extends State wit return null; } catch (e, s) { DialogUtil.errorDefault(context); - LogUtil.requestAPIFailed("proccessRequest.php", "", "Consulta de Mensagems", e, s); + LogUtil.requestAPIFailed( + "proccessRequest.php", "", "Consulta de Mensagems", e, s); setState(() { _hasData = false; _loading = false; @@ -168,12 +175,12 @@ class _MessageHistoryPageWidgetState extends State wit ptText: 'Histórico de Mensagens', ), style: FlutterFlowTheme.of(context).headlineMedium.override( - fontFamily: 'Nunito', - color: FlutterFlowTheme.of(context).primaryText, - fontSize: 17.0, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), - ), + fontFamily: 'Nunito', + color: FlutterFlowTheme.of(context).primaryText, + fontSize: 17.0, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey('Nunito'), + ), ), actions: const [], centerTitle: true, @@ -193,12 +200,12 @@ class _MessageHistoryPageWidgetState extends State wit labelColor: FlutterFlowTheme.of(context).primaryText, unselectedLabelColor: FlutterFlowTheme.of(context).primaryText, labelStyle: FlutterFlowTheme.of(context).titleMedium.override( - fontFamily: FlutterFlowTheme.of(context).titleMediumFamily, - fontSize: 13.0, - letterSpacing: 0.0, - useGoogleFonts: GoogleFonts.asMap().containsKey( - FlutterFlowTheme.of(context).titleMediumFamily), - ), + fontFamily: FlutterFlowTheme.of(context).titleMediumFamily, + fontSize: 13.0, + letterSpacing: 0.0, + useGoogleFonts: GoogleFonts.asMap().containsKey( + FlutterFlowTheme.of(context).titleMediumFamily), + ), unselectedLabelStyle: const TextStyle(), indicatorColor: FlutterFlowTheme.of(context).primary, padding: const EdgeInsets.all(4.0), @@ -232,19 +239,16 @@ class _MessageHistoryPageWidgetState extends State wit mainAxisSize: MainAxisSize.max, children: [ Center( - child: Text( - FFLocalizations.of(context).getVariableText( + child: Text(FFLocalizations.of(context).getVariableText( ptText: "Nenhuma mensagem encontrada!", - enText: "No message found" - ) - ), + enText: "No message found")), ) ], ), ) else if (_hasData == true || _pageNumber >= 1) Expanded( - child: FutureBuilder( + child: FutureBuilder( future: _messageFuture, builder: (context, snapshot) { return ListView.builder( @@ -255,8 +259,7 @@ class _MessageHistoryPageWidgetState extends State wit itemBuilder: (context, index) { final item = _messageWrap[index]; return _item(context, item); - } - ); + }); }, ), ), @@ -280,7 +283,8 @@ class _MessageHistoryPageWidgetState extends State wit ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( - FFLocalizations.of(context).getVariableText(ptText: "Não há mais dados.", enText: "No more data."), + FFLocalizations.of(context).getVariableText( + ptText: "Não há mais dados.", enText: "No more data."), ), duration: const Duration(seconds: 3), backgroundColor: FlutterFlowTheme.of(context).primary, @@ -288,7 +292,6 @@ class _MessageHistoryPageWidgetState extends State wit ); } - Widget _item(BuildContext context, dynamic jsonBody) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 15), @@ -314,8 +317,8 @@ class _MessageHistoryPageWidgetState extends State wit jsonBody['MSG_DESTINO_TP'] == 'T' ? Icons.language : jsonBody['MSG_DESTINO_TP'] == 'P' - ? Icons.person - : Icons.home, + ? Icons.person + : Icons.home, color: FlutterFlowTheme.of(context).primary, size: 25, ), @@ -340,7 +343,8 @@ class _MessageHistoryPageWidgetState extends State wit padding: const EdgeInsets.only(left: 5), child: Icon( Icons.history, - color: FlutterFlowTheme.of(context).customColor6, + color: + FlutterFlowTheme.of(context).customColor6, size: 15, ), ), @@ -351,7 +355,7 @@ class _MessageHistoryPageWidgetState extends State wit fontWeight: FontWeight.bold, fontSize: 10, color: - FlutterFlowTheme.of(context).customColor6, + FlutterFlowTheme.of(context).customColor6, ), overflow: TextOverflow.ellipsis, ), @@ -366,7 +370,8 @@ class _MessageHistoryPageWidgetState extends State wit padding: const EdgeInsets.only(left: 5), child: Icon( Icons.message, - color: FlutterFlowTheme.of(context).customColor6, + color: + FlutterFlowTheme.of(context).customColor6, size: 15, ), ), @@ -388,7 +393,4 @@ class _MessageHistoryPageWidgetState extends State wit ), )); } - } - - From 5527f35e25045e2c3e8138e46f9b189693b03900 Mon Sep 17 00:00:00 2001 From: jantunesmesias Date: Tue, 13 Aug 2024 09:21:14 -0300 Subject: [PATCH 2/5] WIP --- .../details_component_action.dart | 2 + ...iter_vistor_template_component_widget.dart | 2 - ...earch_modal_template_component_widget.dart | 2 - .../schedule_complete_visit_page_widget.dart | 45 ++++++++----------- .../visit_history_page_widget.dart | 8 +--- 5 files changed, 22 insertions(+), 37 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 21e7808a..dd023556 100644 --- a/lib/components/templates_components/details_component/details_component_action.dart +++ b/lib/components/templates_components/details_component/details_component_action.dart @@ -18,7 +18,9 @@ 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']) == diff --git a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart index 4172d6bf..7207e724 100644 --- a/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart +++ b/lib/components/templates_components/regisiter_vistor_template_component/regisiter_vistor_template_component_widget.dart @@ -237,10 +237,8 @@ class _RegisiterVistorTemplateComponentWidgetState ), onChanged: (value) { _model.debounce(() async { - log('data'); var data = await _model.getVisitanteByDocument( value, context); - log('data: $data'); setState(() { _isVisitorRegistered = data; }); diff --git a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart index b545ed9f..dcec2626 100644 --- a/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart +++ b/lib/components/templates_components/visitor_search_modal_template_component/visitor_search_modal_template_component_widget.dart @@ -479,7 +479,6 @@ class _VisitorSearchModalTemplateComponentWidgetState PhpGroup.getVisitorByDocCall .vistanteId((_model.getVisitorByDoc?.jsonBody ?? '')) != null) { - log('visitor found: ${PhpGroup.getVisitorByDocCall.vistanteId((_model.getVisitorByDoc?.jsonBody ?? ''))}'); _model.addToVisitors(PhpGroup.getVisitorByDocCall.visitante( (_model.getVisitorByDoc?.jsonBody ?? ''), )); @@ -498,7 +497,6 @@ class _VisitorSearchModalTemplateComponentWidgetState ); }, ).then((value) => safeSetState(() { - log('value: $value'); if (value != null) { addVisitor(context); } 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 f640d116..2b8c7afb 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 @@ -75,7 +75,7 @@ class _ScheduleCompleteVisitPageWidgetState .toList() .cast(); _model.visitorStrList = widget.visitorStrList!; - setState(() {}); + safeSetState(() {}); } else { return; } @@ -85,7 +85,7 @@ class _ScheduleCompleteVisitPageWidgetState vsync: this, length: 2, initialIndex: 0, - )..addListener(() => setState(() {})); + )..addListener(() => safeSetState(() {})); _model.textController1 ??= TextEditingController(); _model.textFieldFocusNode1 ??= FocusNode(); @@ -116,7 +116,7 @@ class _ScheduleCompleteVisitPageWidgetState if (newItems.isNotEmpty) { _visitHistoryList.addAll(newItems); _visitHistoryLoadingIdx++; - setState(() {}); + safeSetState(() {}); } } @@ -146,8 +146,7 @@ class _ScheduleCompleteVisitPageWidgetState key: scaffoldKey, backgroundColor: FlutterFlowTheme.of(context).primaryBackground, appBar: appBarScheduleCompleteVisit(context), - body: - bodyScheduleCompleteVisit(context, _model, setState, safeSetState), + body: bodyScheduleCompleteVisit(context, _model, safeSetState), ), ); } @@ -191,11 +190,8 @@ PreferredSizeWidget appBarScheduleCompleteVisit(BuildContext context) { ); } -Widget bodyScheduleCompleteVisit( - BuildContext context, - ScheduleCompleteVisitPageModel _model, - Function setState, - Function safeSetState) { +Widget bodyScheduleCompleteVisit(BuildContext context, + ScheduleCompleteVisitPageModel _model, Function safeSetState) { return SafeArea( top: true, child: Column( @@ -237,12 +233,12 @@ Widget bodyScheduleCompleteVisit( child: TabBarView( controller: _model.tabBarController, children: [ - scheduleVisit(context, _model, setState, safeSetState), + scheduleVisit(context, _model, safeSetState), wrapWithModel( model: _model, child: VisitHistoryWidget(), updateCallback: () { - setState(() {}); + safeSetState(() {}); }, updateOnChange: true), ], @@ -253,11 +249,8 @@ Widget bodyScheduleCompleteVisit( ); } -Widget scheduleVisit( - BuildContext context, - ScheduleCompleteVisitPageModel _model, - Function setState, - Function safeSetState) { +Widget scheduleVisit(BuildContext context, + ScheduleCompleteVisitPageModel _model, Function safeSetState) { return SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.max, @@ -512,7 +505,7 @@ Widget scheduleVisit( ); }); } - setState(() { + safeSetState(() { _model.textController1?.text = dateTimeFormat( 'd/M/y H:mm:ss', _model.datePicked1, @@ -760,7 +753,7 @@ Widget scheduleVisit( ); }); } - setState(() { + safeSetState(() { _model.textController2?.text = dateTimeFormat( 'd/M/y H:mm:ss', _model.datePicked2, @@ -896,7 +889,7 @@ Widget scheduleVisit( onPressed: () async { _model.removeFromVisitorJsonList( visitorListViewItem); - setState(() {}); + safeSetState(() {}); }, icon: const Icon(Icons.close), ), @@ -946,13 +939,13 @@ Widget scheduleVisit( visitorsParam! .toList() .cast(); - setState(() {}); + safeSetState(() {}); }, getDocs: (docsParam) async { _model.visitorStrList = strListToStr( docsParam!.toList()); - setState(() {}); + safeSetState(() {}); }, ), ), @@ -1125,7 +1118,7 @@ Widget scheduleVisit( .reasonsMotDescStrList( dropDownGetDadosResponse.jsonBody, ), - onChanged: (val) => setState( + onChanged: (val) => safeSetState( () => _model.dropDownValue1 = val), width: double.infinity, height: double.infinity, @@ -1250,7 +1243,7 @@ Widget scheduleVisit( .levelNACDescricaoStrList( dropDownGetDadosResponse.jsonBody, ), - onChanged: (val) => setState( + onChanged: (val) => safeSetState( () => _model.dropDownValue2 = val), width: double.infinity, height: double.infinity, @@ -1381,7 +1374,7 @@ Widget scheduleVisit( Switch.adaptive( value: _model.switchValue!, onChanged: (newValue) async { - setState(() => _model.switchValue = newValue); + safeSetState(() => _model.switchValue = newValue); }, applyCupertinoTheme: false, focusColor: FlutterFlowTheme.of(context).primary, @@ -1657,7 +1650,7 @@ Widget scheduleVisit( } }); - setState(() {}); + safeSetState(() {}); }); }, ), diff --git a/lib/pages/visit_history_page/visit_history_page_widget.dart b/lib/pages/visit_history_page/visit_history_page_widget.dart index fc5a818e..c502759a 100644 --- a/lib/pages/visit_history_page/visit_history_page_widget.dart +++ b/lib/pages/visit_history_page/visit_history_page_widget.dart @@ -45,12 +45,10 @@ class _VisitHistoryWidgetState extends State { ), ); - log('API response: ${response.jsonBody}'); - var newVisits = response.jsonBody['visitas'] as List?; // Ajuste conforme a estrutura da resposta if (newVisits != null && newVisits.isNotEmpty) { - setState(() { + safeSetState(() { visitaWrap.addAll(newVisits); }); return response; @@ -95,8 +93,6 @@ class _VisitHistoryWidgetState extends State { ); } - log('[A] - ${visitaWrap.length.toString()}'); - return ListView.builder( itemCount: visitaWrap.length + 1, shrinkWrap: true, @@ -114,7 +110,6 @@ class _VisitHistoryWidgetState extends State { } final visitaWrapItem = visitaWrap[index]; - log('[B] - ${visitaWrap.length.toString()}'); return CardItemTemplateComponentWidget( imagePath: @@ -183,7 +178,6 @@ class _VisitHistoryWidgetState extends State { ); }, ).whenComplete(() { - log('Dialog closed'); // updateVisitFuture(); _fetchVisits().then((response) { safeSetState(() { From 60647a708dc158e023c7e29aa50fa08746f0d57a Mon Sep 17 00:00:00 2001 From: jantunesmesias Date: Tue, 13 Aug 2024 11:01:24 -0300 Subject: [PATCH 3/5] WIP --- .../pushNotificationService.dart | 4 +- .../details_component_action.dart | 28 +++++-------- .../schedule_complete_visit_page_widget.dart | 40 +++++++++++++++++-- 3 files changed, 49 insertions(+), 23 deletions(-) diff --git a/lib/backend/push_notification/pushNotificationService.dart b/lib/backend/push_notification/pushNotificationService.dart index 537e780a..c4a068b7 100644 --- a/lib/backend/push_notification/pushNotificationService.dart +++ b/lib/backend/push_notification/pushNotificationService.dart @@ -288,7 +288,9 @@ class PushNotificationService { } static Future _firebaseMessagingBackgroundHandler( - RemoteMessage message) async {} + RemoteMessage message) async { + log('Handling a background message: ${message.messageId}'); + } } class NotificationHandler { 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 dd023556..d3805086 100644 --- a/lib/components/templates_components/details_component/details_component_action.dart +++ b/lib/components/templates_components/details_component/details_component_action.dart @@ -10,6 +10,7 @@ import 'package:hub/flutter_flow/flutter_flow_util.dart'; import 'package:hub/flutter_flow/flutter_flow_widgets.dart'; import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; +import 'package:hub/pages/schedule_complete_visit_page/schedule_complete_visit_page_widget.dart'; import 'package:rxdart/rxdart.dart'; import 'package:share_plus/share_plus.dart'; @@ -111,24 +112,15 @@ Widget buildDetails( Navigator.pop(context); Navigator.pop(context); - context.pushNamed( - 'scheduleCompleteVisitPage', - queryParameters: { - 'dropdownValue1': visitaWrapItem['MOT_DESCRICAO'], - 'dropdownValue2': serializeParam( - visitaWrapItem['NAC_DESCRICAO'], - ParamType.String, - ), - 'visitorStrList': serializeParam( - visitaWrapItem['VTE_DOCUMENTO'], - ParamType.String, - ), - 'visitorJsonList': serializeParam( - [visitaWrapItem], - ParamType.JSON, - isList: true, - ), - }.withoutNulls, + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ScheduleCompleteVisitPageWidget( + dropdownValue1: visitaWrapItem['MOT_DESCRICAO'], + dropdownValue2: visitaWrapItem['NAC_DESCRICAO'], + visitorJsonList: [visitaWrapItem], + visitorStrList: visitaWrapItem['VTE_DOCUMENTO'], + )), ); }, options: FFButtonOptions( 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 2b8c7afb..16f06d15 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 @@ -30,10 +30,14 @@ import 'package:provider/provider.dart'; class ScheduleCompleteVisitPageWidget extends StatefulWidget { const ScheduleCompleteVisitPageWidget({ super.key, + this.dropdownValue1, + this.dropdownValue2, this.visitorStrList, this.visitorJsonList, }); + final String? dropdownValue1; + final String? dropdownValue2; final String? visitorStrList; final List? visitorJsonList; @@ -75,12 +79,23 @@ class _ScheduleCompleteVisitPageWidgetState .toList() .cast(); _model.visitorStrList = widget.visitorStrList!; + + safeSetState(() {}); + } else { + return; + } + + 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; } }); - _model.tabBarController = TabController( vsync: this, length: 2, @@ -1075,7 +1090,6 @@ Widget scheduleVisit(BuildContext context, atividade: 'getDados', ), builder: (context, snapshot) { - // Customize what your widget looks like when it's loading. if (!snapshot.hasData) { return Center( child: SizedBox( @@ -1095,14 +1109,32 @@ Widget scheduleVisit(BuildContext context, PhpGroup.getDadosCall.reasonsJsonList( dropDownGetDadosResponse.jsonBody, ); + // Algoritmo de match + 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(); + }); + } + } + return FlutterFlowDropDown( fillColor: FlutterFlowTheme.of(context) .primaryBackground, controller: _model.dropDownValueController1 ??= FormFieldController( - _model.dropDownValue1 ??= '', - ), + _model.dropDownValue1 ?? ''), options: reasonsJsonList != null && reasonsJsonList != [] ? List.from( From 5a67d5d3f9336df6121deb06830df20ff692750e Mon Sep 17 00:00:00 2001 From: jantunesmesias Date: Tue, 13 Aug 2024 11:19:27 -0300 Subject: [PATCH 4/5] WIP --- .../schedule_complete_visit_page_widget.dart | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) 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 16f06d15..05d0a656 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 @@ -1109,7 +1109,7 @@ Widget scheduleVisit(BuildContext context, PhpGroup.getDadosCall.reasonsJsonList( dropDownGetDadosResponse.jsonBody, ); - // Algoritmo de match + // Algoritmo de match // PODE MANDAR DE VASCO if (_model.dropDownValue1 != null && _model.dropDownValue1!.isNotEmpty) { final matchedValue = @@ -1597,24 +1597,14 @@ Widget scheduleVisit(BuildContext context, child: Dialog( alignment: Alignment.topCenter, child: SizedBox( - // width: MediaQuery.of(context).size.width, - // height: MediaQuery.of(context).size.height * 0.7, - // child: VisitDetailsModalTemplateComponentWidget( - // visitStartDateStr: _model.textController1.text, - // visitEndDateStr: _model.textController2.text, - // visitReasonStr: _model.dropDownValue1, - // visitLevelStr: _model.dropDownValue2, - // visitTempStr: - // _model.switchValue == true ? 'Sim' : 'Não', - // visitObsStr: _model.textController3.text, - // visitorStrList: _model.visitorStrList, - // visitorJsonList: _model.visitorJsonList, - // updateToggleIdx: () async {}, - // repeatVisitSchedule: () async {}, - // ), child: VisitRequestTemplateComponentWidget( buttons: [ - FlutterFlowIconButton( + FFButtonWidget( + text: FFLocalizations.of(context) + .getVariableText( + enText: 'Done', + ptText: 'Confirmar', + ), icon: const Icon(Icons.done), onPressed: () async { log('visitorStrList ${_model.visitorStrList}'); @@ -1685,6 +1675,23 @@ Widget scheduleVisit(BuildContext context, safeSetState(() {}); }); }, + options: FFButtonOptions( + width: 130, + height: 40, + color: FlutterFlowTheme.of(context) + .primaryBackground, + elevation: 0, + textStyle: TextStyle( + color: FlutterFlowTheme.of(context) + .primaryText, + ), + borderSide: BorderSide( + color: FlutterFlowTheme.of(context) + .primaryBackground, + width: 1, + ), + // borderRadius: 12, + ), ), ], imagePath: From 91d219e157da9d05006663eb0ec3ebe9169c9c06 Mon Sep 17 00:00:00 2001 From: Ivan Antunes Date: Tue, 13 Aug 2024 16:57:02 -0300 Subject: [PATCH 5/5] 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)