Browse Source

fix(settings): 修复更新检查对话框关闭的可靠性问题

改进对话框关闭逻辑,使用显式状态跟踪和多种关闭方式确保对话框能正确关闭。同时优化颜色透明度设置方式。
weicu
lxm 1 year ago
parent
commit
2dbcf0cfa8
  1. 31
      lib/modules/settings/controllers/settings_controller.dart

31
lib/modules/settings/controllers/settings_controller.dart

@ -482,8 +482,12 @@ class SettingsController extends GetxController {
if (isCheckingUpdate) return; if (isCheckingUpdate) return;
isCheckingUpdate = true; isCheckingUpdate = true;
// 用于跟踪我们的对话框
bool dialogShown = false;
try { try {
// 显示加载提示 // 显示加载提示
dialogShown = true;
Get.dialog( Get.dialog(
const Center( const Center(
child: CircularProgressIndicator(), child: CircularProgressIndicator(),
@ -494,8 +498,12 @@ class SettingsController extends GetxController {
final versionService = VersionUpdateService.to; final versionService = VersionUpdateService.to;
final updateInfo = await versionService.checkForUpdate(); final updateInfo = await versionService.checkForUpdate();
// 关闭加载提示 // 关闭加载提示 - 使用精确的关闭方式
Get.back(); if (dialogShown) {
dialogShown = false;
// 直接关闭最顶层的对话框,不依赖状态判断
Navigator.of(Get.overlayContext!).pop();
}
if (updateInfo.hasUpdate) { if (updateInfo.hasUpdate) {
// 显示更新对话框 // 显示更新对话框
@ -508,21 +516,30 @@ class SettingsController extends GetxController {
.tr //当前已是最新版本 .tr //当前已是最新版本
.replaceAll('{version}', updateInfo.currentVersion), .replaceAll('{version}', updateInfo.currentVersion),
snackPosition: SnackPosition.TOP, snackPosition: SnackPosition.TOP,
backgroundColor: Colors.green.withOpacity(0.8), backgroundColor: Colors.green.withValues(alpha: 0.8),
colorText: Colors.white, colorText: Colors.white,
); );
} }
} catch (e) { } catch (e) {
// 关闭加载提示 // 关闭加载提示 - 异常情况下的可靠关闭
if (Get.isDialogOpen == true) { if (dialogShown) {
Get.back(closeOverlays: true); dialogShown = false;
try {
// 尝试直接关闭
Navigator.of(Get.overlayContext!).pop();
} catch (popError) {
// 如果直接关闭失败,使用备用方案
if (Get.isDialogOpen == true) {
Get.back();
}
}
} }
Get.snackbar( Get.snackbar(
'error'.tr, 'error'.tr,
'networkErrorRetry'.tr, // 网络错误,请稍后重试 'networkErrorRetry'.tr, // 网络错误,请稍后重试
snackPosition: SnackPosition.TOP, snackPosition: SnackPosition.TOP,
backgroundColor: Colors.red.withOpacity(0.8), backgroundColor: Colors.red.withValues(alpha: 0.8),
colorText: Colors.white, colorText: Colors.white,
); );
} finally { } finally {

Loading…
Cancel
Save