fix: twice exception onLogin

This commit is contained in:
J. A. Messias 2024-12-04 17:47:56 -03:00
parent 6cd090f361
commit c6840638c7
1 changed files with 18 additions and 16 deletions

View File

@ -18,25 +18,28 @@ import '../../utils/log_util.dart';
class AuthenticationService {
static Future<void> 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<dynamic> 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<dynamic> 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());
}
}
}