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); DialogUtil.errorDefault(context);
} else { } else {
DialogUtil.error(context, response.jsonBody['error_msg'].toString()); DialogUtil.error(context, response.jsonBody['error_msg'].toString());
DialogUtil.error(context, response.jsonBody['error_msg'].toString());
} }
} }
} }

View File

@ -198,17 +198,35 @@ class LocalizationService {
} }
} }
static void _handleError(BuildContext context, String errorMsg) { static void _handleError(BuildContext context, String errorMsg) async {
AuthenticationService.signOut(context); final String devUUID = await StorageHelper().get(SQLiteStorageKey.devUUID.value, Storage.SQLiteStorage) ?? '';
DialogUtil.error(context, errorMsg); 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 { static Future<bool> _handleUnavailable(BuildContext context, List<dynamic> locals) async {
log('() => isUnavailable'); log('() => isUnavailable');
try { try {
await StorageHelper().set(SQLiteStorageKey.clientUUID.value, locals[0]['CLI_ID'], Storage.SQLiteStorage); await StorageHelper().set(SQLiteStorageKey.clientUUID.value, locals[0]['CLI_ID'], Storage.SQLiteStorage);
await StorageHelper() await StorageHelper().set(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID'], Storage.SQLiteStorage);
.set(SQLiteStorageKey.ownerUUID.value, locals[0]['CLU_OWNER_ID'], Storage.SQLiteStorage);
await StorageHelper().set(SQLiteStorageKey.clientName.value, locals[0]['CLI_NOME'], Storage.SQLiteStorage); await StorageHelper().set(SQLiteStorageKey.clientName.value, locals[0]['CLI_NOME'], Storage.SQLiteStorage);
var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A'); var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A');
if (response.jsonBody['error'] == true) { if (response.jsonBody['error'] == true) {
@ -287,7 +305,8 @@ class LocalizationService {
jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty jsonBody['petAmountRegister'] != null && jsonBody['petAmountRegister'].toString().isEmpty
? '0' ? '0'
: jsonBody['petAmountRegister'].toString(), : jsonBody['petAmountRegister'].toString(),
Storage.SQLiteStorage); Storage.SQLiteStorage
);
await StorageHelper() await StorageHelper()
.set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage); .set(SQLiteStorageKey.userName.value, jsonBody['visitado']['VDO_NOME'], Storage.SQLiteStorage);
} }