fix handleError localization service

This commit is contained in:
J. A. Messias 2024-11-06 14:32:45 -03:00
parent 746e02ee5f
commit fd7402547e
2 changed files with 29 additions and 9 deletions

View File

@ -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);
}
}
}
}

View File

@ -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<bool> _handleUnavailable(BuildContext context, List<dynamic> 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);
}
}
}