From 2a5acf1016c3c4587f5a932a86aca24c31ef056b Mon Sep 17 00:00:00 2001 From: jantunesmesias Date: Wed, 7 Aug 2024 10:22:48 -0300 Subject: [PATCH] WIP --- lib/actions/actions.dart | 3 +- lib/backend/api_requests/api_calls.dart | 60 +-- .../details_component_action.dart | 39 +- lib/flutter_flow/flutter_flow_util.dart | 24 +- .../preferences_settings_model.dart | 117 +++--- .../schedule_complete_visit_page_model.dart | 6 +- .../schedule_complete_visit_page_widget.dart | 391 +++++++++--------- .../visit_history_page_model.dart | 10 +- .../visit_history_page_widget.dart | 22 +- 9 files changed, 356 insertions(+), 316 deletions(-) diff --git a/lib/actions/actions.dart b/lib/actions/actions.dart index ecd87cf3..49d9cda7 100644 --- a/lib/actions/actions.dart +++ b/lib/actions/actions.dart @@ -344,7 +344,6 @@ Future visitRequestComponentAction( if (respondeSolicitacaoCall.statusCode == 200) { log('jsonBody: ${respondeSolicitacaoCall.jsonBody}; actionValue: $actionValue; refUUID: $refUUID; responseValue: $responseValue; vteUUID: $vteUUID; status: ${respondeSolicitacaoCall.jsonBody['error']}'); - return !respondeSolicitacaoCall.jsonBody['error']; } else { log('headers: ${respondeSolicitacaoCall.headers}'); @@ -485,8 +484,10 @@ Future changeStatusAction( if (!context.mounted) return; if (blockVisitRequest == true) { log('Bloqueado'); + return true; } else { log('Erro ao bloquear'); + return false; } break; default: diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index b198f4d3..d6009dae 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -1370,39 +1370,53 @@ class PostProvVisitSchedulingCall { } class GetVisitsCall { - Future call({ + Stream call({ String? devUUID = '', String? userUUID = '', String? cliID = '', String? atividade = '', int? pageSize, int? pageNumber, - }) async { + }) { final baseUrl = PhpGroup.getBaseUrl(); + final StreamController controller = StreamController(); - return ApiManager.instance.makeApiCall( - callName: 'getVisits', - apiUrl: '$baseUrl/processRequest.php', - callType: ApiCallType.POST, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', + Future.microtask( + () async { + try { + final response = await ApiManager.instance.makeApiCall( + callName: 'getVisits', + apiUrl: '$baseUrl/processRequest.php', + callType: ApiCallType.POST, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + params: { + 'devUUID': devUUID, + 'userUUID': userUUID, + 'cliID': cliID, + 'atividade': atividade, + 'pageSize': pageSize, + 'pageNumber': pageNumber, + }, + bodyType: BodyType.X_WWW_FORM_URL_ENCODED, + returnBody: true, + encodeBodyUtf8: false, + decodeUtf8: false, + cache: false, + isStreamingApi: false, + alwaysAllowBody: false, + ); + controller.add(response); + controller.close(); + } catch (e) { + controller.addError(e); + controller.close(); + } }, - params: { - 'devUUID': devUUID, - 'userUUID': userUUID, - 'cliID': cliID, - 'atividade': atividade, - 'pageSize': pageSize, - 'pageNumber': pageNumber, - }, - bodyType: BodyType.X_WWW_FORM_URL_ENCODED, - returnBody: true, - encodeBodyUtf8: false, - decodeUtf8: false, - cache: false, - isStreamingApi: false, - alwaysAllowBody: false, ); + + return controller.stream; } bool? error(dynamic response) => castToType(getJsonField( 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 0997c02d..bf7df5fe 100644 --- a/lib/components/templates_components/details_component/details_component_action.dart +++ b/lib/components/templates_components/details_component/details_component_action.dart @@ -5,6 +5,7 @@ import 'package:hub/app_state.dart'; import 'package:hub/components/templates_components/details_component/details_component_widget.dart'; import 'package:hub/flutter_flow/flutter_flow_icon_button.dart'; import 'package:hub/flutter_flow/flutter_flow_theme.dart'; +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'; @@ -105,13 +106,47 @@ Widget buildDetails( ptText: 'Sim', ), onPressed: () async { - await changeStatusAction?.call( + await changeStatusAction + ?.call( context, 'B', visitaWrapItem['VAW_REF'] ?? '', 'Mensagem', visitaWrapItem['VTE_ID'] ?? '', - ); + ) + .then((value) { + Navigator.pop(context); + if (value == false) { + showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Error blocking visit', + ptText: 'Erro ao bloquear visita', + ), + true, + ); + } else if (value == true) { + showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Success canceling visit', + ptText: 'Succeso ao cancelar visita', + ), + false, + ); + } + }).catchError((err, stack) { + debugPrint('Error: $err'); + debugPrint('Stack: $stack'); + showSnackbar( + context, + FFLocalizations.of(context).getVariableText( + enText: 'Error blocking visit', + ptText: 'Erro ao bloquear visita', + ), + true, + ); + }); }, options: FFButtonOptions( width: 100, diff --git a/lib/flutter_flow/flutter_flow_util.dart b/lib/flutter_flow/flutter_flow_util.dart index 8a3cc1be..b2c3e3fb 100644 --- a/lib/flutter_flow/flutter_flow_util.dart +++ b/lib/flutter_flow/flutter_flow_util.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:collection/collection.dart'; import 'package:from_css_color/from_css_color.dart'; +import 'package:hub/flutter_flow/flutter_flow_theme.dart'; import 'dart:math' show pow, pi, sin; import 'package:intl/intl.dart'; import 'package:json_path/json_path.dart'; @@ -505,7 +506,8 @@ void setDarkModeSetting(BuildContext context, ThemeMode themeMode) => void showSnackbar( BuildContext context, - String message, { + String message, + bool error, { bool loading = false, int duration = 4, }) { @@ -515,20 +517,32 @@ void showSnackbar( content: Row( children: [ if (loading) - const Padding( - padding: EdgeInsetsDirectional.only(end: 10.0), + Padding( + padding: const EdgeInsetsDirectional.only(end: 10.0), child: SizedBox( height: 20, width: 20, child: CircularProgressIndicator( - color: Colors.white, + color: FlutterFlowTheme.of(context).info, ), ), ), - Text(message), + Text( + message, + style: TextStyle( + color: FlutterFlowTheme.of(context).info, + ), + ), ], ), duration: Duration(seconds: duration), + backgroundColor: error + ? FlutterFlowTheme.of(context).error + : FlutterFlowTheme.of(context).success, + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(30), + ), ), ); } diff --git a/lib/pages/preferences_settings_page/preferences_settings_model.dart b/lib/pages/preferences_settings_page/preferences_settings_model.dart index 2d30ed52..1a3ff528 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_model.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_model.dart @@ -282,68 +282,49 @@ class PreferencesPageModel with ChangeNotifier { tarefa: 'I', ) .then((value) { - FFAppState().deleteCliUUID(); - FFAppState().deleteLocal(); - FFAppState().deleteOwnerUUID(); - Navigator.pop(context); - Navigator.pop(context); + log(value.jsonBody['error'].toString()); + if (value.jsonBody['error'] == false) { + FFAppState().deleteCliUUID(); + FFAppState().deleteLocal(); + FFAppState().deleteOwnerUUID(); + Navigator.pop(context); + Navigator.pop(context); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - FFLocalizations.of(context).getVariableText( - enText: 'Device unlinked successfully', - ptText: - 'Dispositivo desvinculado com sucesso', - ), - style: TextStyle( - color: FlutterFlowTheme.of(context).info, + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text( + FFLocalizations.of(context).getVariableText( + enText: 'Device unlinked successfully', + ptText: + 'Dispositivo desvinculado com sucesso', + ), + style: TextStyle( + color: + FlutterFlowTheme.of(context).info)), + backgroundColor: + FlutterFlowTheme.of(context).success, + duration: const Duration(seconds: 3), + behavior: SnackBarBehavior.floating, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(30), ), ), - backgroundColor: - FlutterFlowTheme.of(context).success, - duration: const Duration(seconds: 3), - behavior: SnackBarBehavior.floating, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(30), - ), - ), - ); - }).catchError((err, stack) { + ); + } + }) + // ignore: body_might_complete_normally_catch_error + .catchError((err, stack) { log(err.toString()); ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( - FFLocalizations.of(context).getVariableText( - enText: 'Error unlinking device', - ptText: 'Erro ao desvincular dispositivo', - ), - style: TextStyle( - color: FlutterFlowTheme.of(context).info, - ), - ), - backgroundColor: - FlutterFlowTheme.of(context).error, - duration: const Duration(seconds: 3), - behavior: SnackBarBehavior.floating, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(30), - ), - ), - ); - }).catchError((err, stack) { - log(err.toString()); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - content: Text( - FFLocalizations.of(context).getVariableText( - enText: 'Error unlinking device', - ptText: 'Erro ao desvincular dispositivo', - ), - style: TextStyle( - color: FlutterFlowTheme.of(context).info, - ), - ), + FFLocalizations.of(context).getVariableText( + enText: 'Error unlinking device', + ptText: 'Erro ao desvincular dispositivo', + ), + style: TextStyle( + color: + FlutterFlowTheme.of(context).info)), backgroundColor: FlutterFlowTheme.of(context).error, duration: const Duration(seconds: 3), @@ -454,18 +435,20 @@ class PreferencesPageModel with ChangeNotifier { userUUID: FFAppState().userUUID, ) .then((value) { - FFAppState().deleteAll(); - FFAppState().isLogged = false; - context.goNamed( - 'welcomePage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); + if (value.jsonBody['error'] == false) { + FFAppState().deleteAll(); + FFAppState().isLogged = false; + context.goNamed( + 'welcomePage', + extra: { + kTransitionInfoKey: const TransitionInfo( + hasTransition: true, + transitionType: PageTransitionType.scale, + alignment: Alignment.bottomCenter, + ), + }, + ); + } }).catchError((err) { log(err.toString()); ScaffoldMessenger.of(context).showSnackBar( diff --git a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart index 23a7f0d0..022d79b9 100644 --- a/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart +++ b/lib/pages/schedule_complete_visit_page/schedule_complete_visit_page_model.dart @@ -12,11 +12,11 @@ import 'package:intl/intl.dart'; class ScheduleCompleteVisitPageModel extends FlutterFlowModel { - final _visitHistoryManager = FutureRequestManager(); - Future visitHistory({ + final _visitHistoryManager = StreamRequestManager(); + Stream visitHistory({ String? uniqueQueryKey, bool? overrideCache, - required Future Function() requestFn, + required Stream Function() requestFn, }) => _visitHistoryManager.performRequest( uniqueQueryKey: uniqueQueryKey, 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 fbd53d4f..79647877 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 @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:auto_size_text/auto_size_text.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; @@ -1694,204 +1696,201 @@ Widget visitHistory( decoration: BoxDecoration( color: FlutterFlowTheme.of(context).primaryBackground, ), - child: SingleChildScrollView( - child: FutureBuilder( - future: _model.visitHistory( - requestFn: () => PhpGroup.getVisitsCall.call( - devUUID: FFAppState().devUUID, - userUUID: FFAppState().userUUID, - cliID: FFAppState().cliUUID, - atividade: 'getVisitas', - ), + child: StreamBuilder( + stream: _model.visitHistory( + requestFn: () => PhpGroup.getVisitsCall.call( + devUUID: FFAppState().devUUID, + userUUID: FFAppState().userUUID, + cliID: FFAppState().cliUUID, + atividade: 'getVisitas', + pageSize: 100, + pageNumber: 1, ), - builder: (context, snapshot) { - // Customize what your widget looks like when it's loading. - if (!snapshot.hasData) { - return Center( - child: SizedBox( - width: 50.0, - height: 50.0, - child: SpinKitCircle( - color: FlutterFlowTheme.of(context).primary, - size: 50.0, - ), - ), - ); - } - final wrapGetVisitsResponse = snapshot.data!; - return Builder( - builder: (context) { - final visitaWrap = PhpGroup.getVisitsCall - .visitasList( - wrapGetVisitsResponse.jsonBody, - ) - ?.toList() ?? - []; - return ListView.builder( - itemCount: visitaWrap.length, - shrinkWrap: true, - scrollDirection: Axis.vertical, - physics: const BouncingScrollPhysics(), - addAutomaticKeepAlives: true, - cacheExtent: 1000.0, - addRepaintBoundaries: true, - addSemanticIndexes: true, - itemBuilder: (context, index) { - final visitaWrapItem = visitaWrap[index]; - // visitaWrap.length, (visitaWrapIndex) { - - return CardItemTemplateComponentWidget( - imageHashMap: Map.from({ - 'key': visitaWrapItem['VTE_DOCUMENTO'] ?? '', - 'value': 'E', - }), - labelsHashMap: Map.from({ - 'Nome:': visitaWrapItem['VTE_NOME'] ?? '', - 'Inicio:': visitaWrapItem['VAW_DTINICIO'] ?? '', - 'Fim:': visitaWrapItem['VAW_DTFIM'] ?? '', - }), - statusHashMap: [ - if (getStatus(visitaWrapItem['VAW_STATUS']) == - status.active) - Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Ativo', - enText: 'Active', - ): FlutterFlowTheme.of(context).warning, - }), - if (getStatus(visitaWrapItem['VAW_STATUS']) == - status.finished) - Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Finalizado', - enText: 'Finished', - ): FlutterFlowTheme.of(context).success, - }), - if (getStatus(visitaWrapItem['VAW_STATUS']) == - status.unknown) - Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Desconhecido', - enText: 'Unknown', - ): FlutterFlowTheme.of(context).alternate, - }), - if (getStatus(visitaWrapItem['VAW_STATUS']) == - status.canceled) - Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Cancelado', - enText: 'Canceled', - ): FlutterFlowTheme.of(context).error, - }), - if (getStatus(visitaWrapItem['VAW_STATUS']) == - status.blocked) - Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Bloqueado', - enText: 'Blocked', - ): FlutterFlowTheme.of(context).error, - }), - if (getStatus(visitaWrapItem['VAW_STATUS']) == - status.inactive) - Map.from({ - FFLocalizations.of(context).getVariableText( - ptText: 'Inactive', - enText: 'Inactive', - ): FlutterFlowTheme.of(context).error, - }), - ], - onTapCardItemAction: () async { - showModalBottomSheet( - isScrollControlled: true, - isDismissible: true, - backgroundColor: Colors.transparent, - useSafeArea: true, - context: context, - builder: (context) { - return buildDetails( - visitaWrapItem, - context, - changeStatusAction, - ); - }, - ).then((_) { - // PushNotificationManager _pushNotificationService = - // PushNotificationManager(); - // _pushNotificationService.onMessageReceived - // .listen((received) { - // if (received.data['click_action'] == - // 'cancel_request') { - // log('Aprovado'); - // _pushNotificationService.dispose(); - // snackbar(context, opt: true); - // context.pushReplacementNamed( - // 'liberationHistory', - // extra: { - // kTransitionInfoKey: const TransitionInfo( - // hasTransition: true, - // transitionType: PageTransitionType.scale, - // alignment: Alignment.bottomCenter, - // ), - // }, - // ); - // } - // }); - }); - // await showModalBottomSheet( - // isScrollControlled: true, - // backgroundColor: Colors.transparent, - // enableDrag: true, - // isDismissible: true, - // useSafeArea: true, - // context: context, - // builder: (context) { - // return GestureDetector( - // onTap: () => _model.unfocusNode.canRequestFocus - // ? FocusScope.of(context) - // .requestFocus(_model.unfocusNode) - // : FocusScope.of(context).unfocus(), - // child: VisitDetailsModalTemplateComponentWidget( - // visitStatusStr: visitaWrapItem['VAW_STATUS'], - // visitStartDateStr: - // visitaWrapItem['VAW_DTINICIO'], - // visitEndDateStr: visitaWrapItem['VAW_DTFIM'], - // visitReasonStr: - // visitaWrapItem['MOT_DESCRICAO'], - // visitLevelStr: - // visitaWrapItem['NAC_DESCRICAO'], - // visitTempStr: - // visitaWrapItem['VTE_UNICA'].toString(), - // visitObsStr: visitaWrapItem['VAW_OBS'], - // visitorImgPath: valueOrDefault( - // "https://freaccess.com.br/freaccess/getImage.php?devUUID=${FFAppState().devUUID}&userUUID=${FFAppState().userUUID}&cliID=${FFAppState().cliUUID}&atividade=getFoto&Documento=${getJsonField( - // visitaWrapItem, - // r'''$.VTE_DOCUMENTO''', - // ).toString()}&tipo=E", - // 'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg', - // ), - // visitorStrList: - // visitaWrapItem['VTE_DOCUMENTO'], - // visitIdStr: visitaWrapItem['VAW_ID'], - // visitStatusColor: - // visitaWrapItem['VAW_STATUS'] == 'A' - // ? FlutterFlowTheme.of(context).success - // : FlutterFlowTheme.of(context).error, - // visitorJsonList: - // PhpGroup.getVisitsCall.visitasList( - // wrapGetVisitsResponse.jsonBody, - // ), - // updateToggleIdx: () async {}, - // repeatVisitSchedule: () async {}, - // ), - // ); - // }, - // ).then((value) => safeSetState(() {})); - }); - }); - }, - ); - }, ), + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + return Center( + child: CircularProgressIndicator( + valueColor: AlwaysStoppedAnimation( + FlutterFlowTheme.of(context).primary, + ), + )); + } else if (snapshot.hasError) { + log('Error: ${snapshot.error}'); + return Center(child: Text('Error: ${snapshot.error}')); + } else if (!snapshot.hasData || snapshot.data!.jsonBody == null) { + log('No data or jsonBody is null'); + return const Center(child: Text('No visits found')); + } + + final wrapGetVisitsResponse = snapshot.data!; + log('Response: ${wrapGetVisitsResponse.jsonBody}'); + + final visitaWrap = PhpGroup.getVisitsCall + .visitasList(wrapGetVisitsResponse.jsonBody) + ?.toList() ?? + []; + log('visitaWrap: $visitaWrap'); + return ListView.builder( + itemCount: visitaWrap.length, + shrinkWrap: true, + scrollDirection: Axis.vertical, + physics: const BouncingScrollPhysics(), + addAutomaticKeepAlives: true, + cacheExtent: 1000.0, + addRepaintBoundaries: true, + addSemanticIndexes: true, + itemBuilder: (context, index) { + final visitaWrapItem = visitaWrap[index]; + return CardItemTemplateComponentWidget( + imageHashMap: Map.from({ + 'key': visitaWrapItem['VTE_DOCUMENTO'] ?? '', + 'value': 'E', + }), + labelsHashMap: Map.from({ + 'Nome:': visitaWrapItem['VTE_NOME'] ?? '', + 'Inicio:': visitaWrapItem['VAW_DTINICIO'] ?? '', + 'Fim:': visitaWrapItem['VAW_DTFIM'] ?? '', + }), + statusHashMap: [ + if (getStatus(visitaWrapItem['VAW_STATUS']) == + status.active) + Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Ativo', + enText: 'Active', + ): FlutterFlowTheme.of(context).warning, + }), + if (getStatus(visitaWrapItem['VAW_STATUS']) == + status.finished) + Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Finalizado', + enText: 'Finished', + ): FlutterFlowTheme.of(context).success, + }), + if (getStatus(visitaWrapItem['VAW_STATUS']) == + status.unknown) + Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Desconhecido', + enText: 'Unknown', + ): FlutterFlowTheme.of(context).alternate, + }), + if (getStatus(visitaWrapItem['VAW_STATUS']) == + status.canceled) + Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Cancelado', + enText: 'Canceled', + ): FlutterFlowTheme.of(context).error, + }), + if (getStatus(visitaWrapItem['VAW_STATUS']) == + status.blocked) + Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Bloqueado', + enText: 'Blocked', + ): FlutterFlowTheme.of(context).error, + }), + if (getStatus(visitaWrapItem['VAW_STATUS']) == + status.inactive) + Map.from({ + FFLocalizations.of(context).getVariableText( + ptText: 'Inactive', + enText: 'Inactive', + ): FlutterFlowTheme.of(context).error, + }), + ], + onTapCardItemAction: () async { + showModalBottomSheet( + isScrollControlled: true, + isDismissible: true, + backgroundColor: Colors.transparent, + useSafeArea: true, + context: context, + builder: (context) { + return buildDetails( + visitaWrapItem, + context, + changeStatusAction, + ); + }, + ).then((_) { + // PushNotificationManager _pushNotificationService = + // PushNotificationManager(); + // _pushNotificationService.onMessageReceived + // .listen((received) { + // if (received.data['click_action'] == + // 'cancel_request') { + // log('Aprovado'); + // _pushNotificationService.dispose(); + // snackbar(context, opt: true); + // context.pushReplacementNamed( + // 'liberationHistory', + // extra: { + // kTransitionInfoKey: const TransitionInfo( + // hasTransition: true, + // transitionType: PageTransitionType.scale, + // alignment: Alignment.bottomCenter, + // ), + // }, + // ); + // } + // }); + }); + // await showModalBottomSheet( + // isScrollControlled: true, + // backgroundColor: Colors.transparent, + // enableDrag: true, + // isDismissible: true, + // useSafeArea: true, + // context: context, + // builder: (context) { + // return GestureDetector( + // onTap: () => _model.unfocusNode.canRequestFocus + // ? FocusScope.of(context) + // .requestFocus(_model.unfocusNode) + // : FocusScope.of(context).unfocus(), + // child: VisitDetailsModalTemplateComponentWidget( + // visitStatusStr: visitaWrapItem['VAW_STATUS'], + // visitStartDateStr: + // visitaWrapItem['VAW_DTINICIO'], + // visitEndDateStr: visitaWrapItem['VAW_DTFIM'], + // visitReasonStr: + // visitaWrapItem['MOT_DESCRICAO'], + // visitLevelStr: + // visitaWrapItem['NAC_DESCRICAO'], + // visitTempStr: + // visitaWrapItem['VTE_UNICA'].toString(), + // visitObsStr: visitaWrapItem['VAW_OBS'], + // visitorImgPath: valueOrDefault( + // "https://freaccess.com.br/freaccess/getImage.php?devUUID=${FFAppState().devUUID}&userUUID=${FFAppState().userUUID}&cliID=${FFAppState().cliUUID}&atividade=getFoto&Documento=${getJsonField( + // visitaWrapItem, + // r'''$.VTE_DOCUMENTO''', + // ).toString()}&tipo=E", + // 'https://storage.googleapis.com/flutterflow-io-6f20.appspot.com/projects/flutter-freaccess-hub-0xgz9q/assets/7ftdetkzc3s0/360_F_64676383_LdbmhiNM6Ypzb3FM4PPuFP9rHe7ri8Ju.jpg', + // ), + // visitorStrList: + // visitaWrapItem['VTE_DOCUMENTO'], + // visitIdStr: visitaWrapItem['VAW_ID'], + // visitStatusColor: + // visitaWrapItem['VAW_STATUS'] == 'A' + // ? FlutterFlowTheme.of(context).success + // : FlutterFlowTheme.of(context).error, + // visitorJsonList: + // PhpGroup.getVisitsCall.visitasList( + // wrapGetVisitsResponse.jsonBody, + // ), + // updateToggleIdx: () async {}, + // repeatVisitSchedule: () async {}, + // ), + // ); + // }, + // ).then((value) => safeSetState(() {})); + }); + }); + }, ), ); } diff --git a/lib/pages/visit_history_page/visit_history_page_model.dart b/lib/pages/visit_history_page/visit_history_page_model.dart index c0c3bed8..2adb1620 100644 --- a/lib/pages/visit_history_page/visit_history_page_model.dart +++ b/lib/pages/visit_history_page/visit_history_page_model.dart @@ -1,5 +1,3 @@ - - import 'package:flutter/material.dart'; import 'package:hub/backend/api_requests/api_manager.dart'; import 'package:hub/flutter_flow/flutter_flow_model.dart'; @@ -8,11 +6,11 @@ import 'package:hub/flutter_flow/request_manager.dart'; import 'package:hub/pages/visit_history_page/visit_history_page_widget.dart'; class VisitHistoryPageModel extends FlutterFlowModel { - final _visitHistoryManager = FutureRequestManager(); - Future visitHistory({ + final _visitHistoryManager = StreamRequestManager(); + Stream visitHistory({ String? uniqueQueryKey, bool? overrideCache, - required Future Function() requestFn, + required Stream Function() requestFn, }) => _visitHistoryManager.performRequest( uniqueQueryKey: uniqueQueryKey, @@ -105,4 +103,4 @@ class VisitHistoryPageModel extends FlutterFlowModel { return false; } -} \ No newline at end of file +} 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 3e813f39..64bfc9c6 100644 --- a/lib/pages/visit_history_page/visit_history_page_widget.dart +++ b/lib/pages/visit_history_page/visit_history_page_widget.dart @@ -17,7 +17,6 @@ import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/visit_history_page/visit_history_page_model.dart'; import 'package:provider/provider.dart'; - class VisitHistoryPageWidget extends StatefulWidget { const VisitHistoryPageWidget({ super.key, @@ -233,8 +232,8 @@ Widget visitHistory( ), ], ), - FutureBuilder( - future: _model.visitHistory( + StreamBuilder( + stream: _model.visitHistory( requestFn: () => PhpGroup.getVisitsCall.call( devUUID: FFAppState().devUUID, userUUID: FFAppState().userUUID, @@ -586,9 +585,8 @@ Widget visitHistory( return FlutterFlowTheme .of(context) .success; - } else if (( - jsonToStr( - getJsonField( + } else if ((jsonToStr( + getJsonField( visitaWrapItem, r'''$.VAW_STATUS''', )) == @@ -614,9 +612,8 @@ Widget visitHistory( return FlutterFlowTheme .of(context) .error; - } else if ( - jsonToStr( - getJsonField( + } else if (jsonToStr( + getJsonField( visitaWrapItem, r'''$.VAW_STATUS''', )) == @@ -655,9 +652,8 @@ Widget visitHistory( ptText: 'Ativo', enText: 'Active', ); - } else if (( - jsonToStr( - getJsonField( + } else if ((jsonToStr( + getJsonField( visitaWrapItem, r'''$.VAW_STATUS''', )) == @@ -754,4 +750,4 @@ Widget visitHistory( ), ), ); -} \ No newline at end of file +}