From c6840638c77b46db5ffe8057dfa445d8862503ed Mon Sep 17 00:00:00 2001 From: "J. A. Messias" Date: Wed, 4 Dec 2024 17:47:56 -0300 Subject: [PATCH] fix: twice exception onLogin --- .../authentication_service.dart | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lib/shared/services/authentication/authentication_service.dart b/lib/shared/services/authentication/authentication_service.dart index ef3e4ffb..ce753550 100644 --- a/lib/shared/services/authentication/authentication_service.dart +++ b/lib/shared/services/authentication/authentication_service.dart @@ -18,25 +18,28 @@ import '../../utils/log_util.dart'; class AuthenticationService { static Future login(BuildContext context) async { - final GetLocalsCall callback = PhpGroup.getLocalsCall; + try { + final GetLocalsCall callback = PhpGroup.getLocalsCall; + final response = await callback.call(); - final response = await callback.call(); + if (response.jsonBody['error']) { + await DialogUtil.errorDefault(context); + return; + } - if (response.jsonBody['error']) { + List locals = response.jsonBody['locais'] ?? []; + + if (locals.isEmpty) { + await StorageHelper().set(SecureStorageKey.haveLocal.value, false); + context.go('/receptionPage'); + } else { + await StorageHelper().set(SecureStorageKey.isLogged.value, true); + context.go('/homePage', extra: {'update': LocalsRepositoryImpl().update}); + } + } catch (e, s) { await DialogUtil.errorDefault(context); - return; + LogUtil.requestAPIFailed('getLocals.php', '', "Get Locals", e, s); } - List locals = response.jsonBody['locais'] ?? []; - - if (locals.isEmpty) { - await StorageHelper().set(SecureStorageKey.haveLocal.value, false); - context.go('/receptionPage'); - } else { - await StorageHelper().set(SecureStorageKey.isLogged.value, true); - context.go('/homePage', extra: {'update': LocalsRepositoryImpl().update}); - } - - } static Future signIn( @@ -86,7 +89,6 @@ class AuthenticationService { await DialogUtil.errorDefault(context); } else { await DialogUtil.error(context, response.jsonBody['error_msg'].toString()); - await DialogUtil.error(context, response.jsonBody['error_msg'].toString()); } } }