From dce7d11a3e61e3cc5724f61206f1cfd62b58a4f7 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Fri, 18 Oct 2024 08:41:56 -0300 Subject: [PATCH] fix: bug do vitassay --- lib/backend/api_requests/api_calls.dart | 2 +- ..._arrow_linked_locals_component_widget.dart | 21 ++++++++--- ...earch_modal_template_component_widget.dart | 7 ++-- lib/main.dart | 3 ++ .../preferences_settings_widget.dart | 22 ------------ .../schedule_complete_visit_page_widget.dart | 4 +-- .../authentication_service.dart | 36 +++++++++---------- .../localization/localization_service.dart | 7 ++-- lib/shared/utils/device_util.dart | 13 +++++++ lib/shared/utils/storage_util.dart | 4 +-- 10 files changed, 61 insertions(+), 58 deletions(-) diff --git a/lib/backend/api_requests/api_calls.dart b/lib/backend/api_requests/api_calls.dart index 7b14e8a5..4665a13e 100644 --- a/lib/backend/api_requests/api_calls.dart +++ b/lib/backend/api_requests/api_calls.dart @@ -840,7 +840,7 @@ class PostScheduleVisitCall { 'unica': unica, 'idMotivo': idMotivo, 'idNAC': idNAC, - 'obs': obs, + 'Obs': obs, 'DevDesc': devDesc, }, bodyType: BodyType.X_WWW_FORM_URL_ENCODED, diff --git a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart index f7eb9c01..0f242373 100644 --- a/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart +++ b/lib/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart @@ -7,6 +7,7 @@ import 'package:hub/shared/utils/dialog_util.dart'; import 'package:hub/shared/utils/log_util.dart'; import 'package:hub/shared/utils/storage_util.dart'; +import '../../../shared/services/authentication/authentication_service.dart'; import '/backend/api_requests/api_calls.dart'; import '/flutter_flow/flutter_flow_theme.dart'; @@ -61,6 +62,14 @@ class _BottomArrowLinkedLocalsComponentWidgetState try { setState(() => _loading = true); var response = await PhpGroup.getLocalsCall.call(); + final bool isError = response.jsonBody['error']; + + + if (isError) { + final String errorMsg = response.jsonBody['error_msg']; + _handleError(context, errorMsg); + return response; + } final List locals = response.jsonBody['locais'] ?? []; @@ -73,11 +82,7 @@ class _BottomArrowLinkedLocalsComponentWidgetState final bool isEnabled = isUnique && isActive; final bool isDisabled = isUnique && isBlocked; - final bool isError = response.jsonBody['error'] == true; - final bool isInvalid = response.jsonBody['error_msg'] == 'Esse dispositivo nao pertence a esse usuario'; - if(isError) DialogUtil.error(context, response.jsonBody['error_msg']); - if(isInvalid) StorageUtil().isLogged = false; - if(isInvalid) context.go('/welcomePage'); + if (!isEmpty) { @@ -119,6 +124,12 @@ class _BottomArrowLinkedLocalsComponentWidgetState return null; } + static void _handleError(BuildContext context, String errorMsg) { + AuthenticationService.signOut(context); + DialogUtil.error(context, errorMsg); + LogUtil.requestAPIFailed('getLocals.php', '{devUUID: ${StorageUtil().devUUID}, cliUUID: ${StorageUtil().userUUID}}', 'Get Locals', errorMsg, StackTrace.current); + } + Future _fetchResponseLink(String status, String cliID) async { try { StorageUtil().cliUUID = cliID; 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 3978059b..29597fc5 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 @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -423,9 +425,8 @@ class _VisitorSearchModalTemplateComponentWidgetState await widget.getVisitors?.call( _model.visitors, ); - await widget.getDocs?.call( - _model.docs, - ); + log('() => docs: ${_model.docs}'); + await widget.getDocs?.call(_model.docs); context.pop(); } diff --git a/lib/main.dart b/lib/main.dart index 9e054785..177038d9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,6 +18,7 @@ import 'package:hub/flutter_flow/internationalization.dart'; import 'package:hub/flutter_flow/nav/nav.dart'; import 'package:hub/pages/forgot_password_page/forgot_password_screen.dart'; import 'package:hub/shared/helpers/shared_preferences_storage_helper.dart'; +import 'package:hub/shared/utils/device_util.dart'; import 'package:hub/shared/utils/storage_util.dart'; import 'package:responsive_framework/responsive_framework.dart'; @@ -265,6 +266,8 @@ class _AppState extends State { void initState() { super.initState(); + log('DeviceUtil: ${DeviceUtil.getDeviceOSVersion()}'); + FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); _appStateNotifier = AppStateNotifier.instance; _router = createRouter(_appStateNotifier); diff --git a/lib/pages/preferences_settings_page/preferences_settings_widget.dart b/lib/pages/preferences_settings_page/preferences_settings_widget.dart index d492d46f..945092b9 100644 --- a/lib/pages/preferences_settings_page/preferences_settings_widget.dart +++ b/lib/pages/preferences_settings_page/preferences_settings_widget.dart @@ -229,27 +229,5 @@ class _PreferencesPageWidgetState extends State { ); } - void logout(BuildContext context) async { - showAlertDialog( - context, - 'Logout', - FFLocalizations.of(context).getVariableText( - enText: 'Are you sure you want to logout?', - ptText: 'Tem certeza', - ), () async { - StorageUtil.purge(); - // setState(() {}); - context.go( - '/welcomePage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); - }); - } } 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 01789f5c..8ce47494 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 @@ -1501,7 +1501,7 @@ Widget scheduleVisit(BuildContext context, ScheduleCompleteVisitPageModel model, .convertDateFormat(model.textController1.text), dtFim: model .convertDateFormat(model.textController2.text), - unica: model.switchValue == true ? 'Sim' : 'Não', + unica: model.switchValue == true ? 'S' : 'N', idMotivo: extractIdToStr(model.dropDownValue1!), idNAC: extractIdToStr(model.dropDownValue2!), obs: model.textController3.text, @@ -1614,7 +1614,7 @@ Widget scheduleVisit(BuildContext context, ScheduleCompleteVisitPageModel model, .toString()) ?? '', 'Single Visit': - model.switchValue == true ? 'Sim' : 'Não', + model.switchValue == true ? 'S' : 'N', if (model.textController3.text.isNotEmpty) 'Observation': model.textController3.text, }, diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index df69ead1..11821a73 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -128,17 +128,15 @@ class AuthenticationService { static Future signOut(BuildContext context) async { await PhpGroup.unregisterDevice.call(); + final Map extra = { + kTransitionInfoKey: const TransitionInfo( + hasTransition: true, + transitionType: PageTransitionType.scale, + alignment: Alignment.bottomCenter, + ), + }; await StorageUtil.purge(); - context.go( - '/welcomePage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); + context.go( '/welcomePage', extra: extra); } static Future forgotPassword(BuildContext context, String email) async { @@ -189,6 +187,13 @@ class AuthenticationService { String content; try { await PhpGroup.deleteAccount.call().then((value) { + final Map extra = { + kTransitionInfoKey: const TransitionInfo( + hasTransition: true, + transitionType: PageTransitionType.scale, + alignment: Alignment.bottomCenter, + ), + }; if (value.jsonBody['error'] == false) { content = FFLocalizations.of(context).getVariableText( enText: 'Account deleted successfully', @@ -196,16 +201,7 @@ class AuthenticationService { ); StorageUtil.purge(); context.pop(); - context.go( - '/welcomePage', - extra: { - kTransitionInfoKey: const TransitionInfo( - hasTransition: true, - transitionType: PageTransitionType.scale, - alignment: Alignment.bottomCenter, - ), - }, - ); + context.go('/welcomePage', extra: extra); } }).catchError((err) { context.pop(); diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 333070d2..2b924722 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -10,6 +10,7 @@ import '../../../components/organism_components/bottom_arrow_linked_locals_compo import '../../../flutter_flow/flutter_flow_util.dart'; import '../../utils/log_util.dart'; import '../../utils/snackbar_util.dart'; +import '../authentication/authentication_service.dart'; class LocalizationService { @@ -70,7 +71,7 @@ class LocalizationService { final bool isAvailable = _isAvailable(); if (isDisabled) { - context.go('/welcomePage'); + AuthenticationService.signOut(context); return true; } else if (isUnavailable) { return await _handleUnavailable(context, locals); @@ -185,9 +186,9 @@ class LocalizationService { } static void _handleError(BuildContext context, String errorMsg) { - StorageUtil().isLogged = false; - context.go('/welcomePage'); + AuthenticationService.signOut(context); DialogUtil.error(context, errorMsg); + LogUtil.requestAPIFailed('getLocals.php', '{devUUID: ${StorageUtil().devUUID}, cliUUID: ${StorageUtil().userUUID}}', 'Get Locals', errorMsg, StackTrace.current); } static Future _handleUnavailable(BuildContext context, List locals) async { log('() => isUnavailable'); diff --git a/lib/shared/utils/device_util.dart b/lib/shared/utils/device_util.dart index 285e4fe2..1009e9e7 100644 --- a/lib/shared/utils/device_util.dart +++ b/lib/shared/utils/device_util.dart @@ -29,4 +29,17 @@ class DeviceUtil { } return null; } + + static Future getDeviceOSVersion() async { + var deviceInfo = DeviceInfoPlugin(); + if (Platform.isIOS) { + var iosDeviceInfo = await deviceInfo.iosInfo; + return iosDeviceInfo.systemVersion; // unique ID on iOS. e.g. 14.5 + } else if (Platform.isAndroid) { + var androidDeviceInfo = await deviceInfo.androidInfo; + return androidDeviceInfo.version.release; // unique ID on Android. e.g . 11 + } + return null; + + } } diff --git a/lib/shared/utils/storage_util.dart b/lib/shared/utils/storage_util.dart index 9c1b5dcf..edcb815c 100644 --- a/lib/shared/utils/storage_util.dart +++ b/lib/shared/utils/storage_util.dart @@ -109,9 +109,9 @@ class StorageUtil { static Future purge() async { try { - // await SecureStorageHelper().purge(); - // await SharedPreferencesStorageHelper().purge(); + await SecureStorageHelper().purge(); await SQLiteStorageHelper().purge(); + // await SharedPreferencesStorageHelper().purge(); } catch (e) { log('Error purging data: $e'); }