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