From fd7402547ee4f322479cd863eeca5d6b2063f117 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 6 Nov 2024 14:32:45 -0300 Subject: [PATCH 1/2] fix handleError localization service --- .../authentication_service.dart | 3 +- .../localization/localization_service.dart | 35 ++++++++++++++----- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index 89be408a..b867c200 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -82,6 +82,7 @@ class AuthenticationService { DialogUtil.errorDefault(context); } else { DialogUtil.error(context, response.jsonBody['error_msg'].toString()); + DialogUtil.error(context, response.jsonBody['error_msg'].toString()); } } } @@ -221,4 +222,4 @@ class AuthenticationService { SnackBarUtil.showSnackBar(context, content, isError: true); } } -} +} \ No newline at end of file diff --git a/lib/shared/services/localization/localization_service.dart b/lib/shared/services/localization/localization_service.dart index 7ca76741..818a2338 100644 --- a/lib/shared/services/localization/localization_service.dart +++ b/lib/shared/services/localization/localization_service.dart @@ -198,17 +198,35 @@ class LocalizationService { } } - static void _handleError(BuildContext context, String errorMsg) { - AuthenticationService.signOut(context); - DialogUtil.error(context, errorMsg); + static void _handleError(BuildContext context, String errorMsg) async { + final String devUUID = await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage) ?? ''; + final String userUUID = await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage) ?? ''; + final bool isAuthenticated = userUUID.isNotEmpty && devUUID.isNotEmpty; + final bool isDevLinked = !errorMsg.contains('Esse dispositivo nao pertence a esse usuario'); + log('() => isLinked: $errorMsg'); + if (isAuthenticated && isDevLinked) await DialogUtil.error(context, errorMsg).whenComplete(() async => await selectLocal(context)); + if (isAuthenticated && !isDevLinked) { + errorMsg = FFLocalizations.of(context).getVariableText( + ptText: 'Não foi possível vincular o dispositivo, tente novamente', + enText: 'Unable to link device, try again', + ); + await DialogUtil.warning(context, errorMsg); + } + if (!isAuthenticated) { + errorMsg = FFLocalizations.of(context).getVariableText( + ptText: 'Erro ao obter credenciais de autenticação', + enText: 'Error getting authentication credentials', + ); + await DialogUtil.error(context, errorMsg); + // await DialogUtil.error(context, errorMsg).whenComplete(() async => await AuthenticationService.signOut(context)); + } } static Future _handleUnavailable(BuildContext context, List locals) async { log('() => isUnavailable'); try { await StorageHelper().set(SQLiteStorageKey.clientUUID.value, locals[0]['CLI_ID'], Storage.SQLiteStorage); - await StorageHelper() - .set(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID'], Storage.SQLiteStorage); + await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID'], Storage.SQLiteStorage); await StorageHelper().set(SQLiteStorageKey.clientName.value, locals[0]['CLI_NOME'], Storage.SQLiteStorage); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); if (response.jsonBody['error'] == true) { @@ -286,9 +304,10 @@ class LocalizationService { SQLiteStorageKey.petAmount.value, jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty ? '0' - : jsonBody['petAmountRegister'].toString(), - Storage.SQLiteStorage); + : jsonBody['petAmountRegister'].toString(), + Storage.SQLiteStorage + ); await StorageHelper() .set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage); } -} +} \ No newline at end of file From 24c1c0ccb9d9ad4ca6c42793aac3a493ccca4be3 Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 6 Nov 2024 14:34:55 -0300 Subject: [PATCH 2/2] WIP --- lib/flutter_flow/nav/nav.dart | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/lib/flutter_flow/nav/nav.dart b/lib/flutter_flow/nav/nav.dart index ba6d63b6..09826746 100644 --- a/lib/flutter_flow/nav/nav.dart +++ b/lib/flutter_flow/nav/nav.dart @@ -80,18 +80,10 @@ GoRouter createRouter(AppStateNotifier appStateNotifier) { builder: (context, _) { return FutureBuilder( future: () async { - final bool isLogged = - await StorageHelper().get(SecureStorageKey.isLogged.value, Storage.SecureStorage) == 'true'; - final bool haveLocal = - await StorageHelper().get(SecureStorageKey.haveLocal.value, Storage.SecureStorage) == 'true'; - final bool haveUserUUID = - (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage)) - ?.isNotEmpty ?? - false; - final bool haveDevUUID = - (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage)) - ?.isNotEmpty ?? - false; + final bool isLogged = await StorageHelper().get(SecureStorageKey.isLogged.value, Storage.SecureStorage) == 'true'; + final bool haveLocal = await StorageHelper().get(SecureStorageKey.haveLocal.value, Storage.SecureStorage) == 'true'; + final bool haveUserUUID = (await StorageHelper().get(SQLiteStorageKey.userUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? false; + final bool haveDevUUID = (await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage))?.isNotEmpty ?? false; if (isLogged && haveDevUUID && haveUserUUID) { return haveLocal ? const HomePageWidget() : const ReceptionPageWidget();