|
|
|
@ -1,4 +1,3 @@ |
|
|
|
import 'package:firebase_auth/firebase_auth.dart' as firebase; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:dio/dio.dart'; |
|
|
|
@ -7,15 +6,11 @@ import '../../../core/themes/theme_service.dart'; |
|
|
|
import '../../../data/services/speech_factory.dart'; |
|
|
|
import '../models/language_model.dart'; |
|
|
|
import 'package:logger/logger.dart'; |
|
|
|
import '../../../data/models/user_Info.dart'; |
|
|
|
import '../../../data/services/ble_manager.dart'; |
|
|
|
|
|
|
|
import 'package:path_provider/path_provider.dart'; |
|
|
|
import 'dart:io'; |
|
|
|
import 'package:package_info_plus/package_info_plus.dart'; |
|
|
|
import 'package:permission_handler/permission_handler.dart'; |
|
|
|
import 'dart:async'; |
|
|
|
import 'package:app_settings/app_settings.dart'; |
|
|
|
import '../../../data/services/version_update_service.dart'; |
|
|
|
import '../../common/widgets/version_update_dialog.dart'; |
|
|
|
|
|
|
|
@ -128,6 +123,8 @@ class SettingsController extends GetxController { |
|
|
|
final appVersion = ''.obs; |
|
|
|
final buildNumber = ''.obs; |
|
|
|
|
|
|
|
bool isCheckingUpdate = false; //状态锁,防止重复检查 |
|
|
|
|
|
|
|
// 权限相关 |
|
|
|
// 权限组,用于在UI中显示 |
|
|
|
final List<Map<String, dynamic>> permissionGroups = [ |
|
|
|
@ -482,8 +479,15 @@ class SettingsController extends GetxController { |
|
|
|
|
|
|
|
/// 手动检查版本更新 |
|
|
|
Future<void> checkForUpdate() async { |
|
|
|
if (isCheckingUpdate) return; |
|
|
|
isCheckingUpdate = true; |
|
|
|
|
|
|
|
// 用于跟踪我们的对话框 |
|
|
|
bool dialogShown = false; |
|
|
|
|
|
|
|
try { |
|
|
|
// 显示加载提示 |
|
|
|
dialogShown = true; |
|
|
|
Get.dialog( |
|
|
|
const Center( |
|
|
|
child: CircularProgressIndicator(), |
|
|
|
@ -494,8 +498,12 @@ class SettingsController extends GetxController { |
|
|
|
final versionService = VersionUpdateService.to; |
|
|
|
final updateInfo = await versionService.checkForUpdate(); |
|
|
|
|
|
|
|
// 关闭加载提示 |
|
|
|
Get.back(); |
|
|
|
// 关闭加载提示 - 使用精确的关闭方式 |
|
|
|
if (dialogShown) { |
|
|
|
dialogShown = false; |
|
|
|
// 直接关闭最顶层的对话框,不依赖状态判断 |
|
|
|
Navigator.of(Get.overlayContext!).pop(); |
|
|
|
} |
|
|
|
|
|
|
|
if (updateInfo.hasUpdate) { |
|
|
|
// 显示更新对话框 |
|
|
|
@ -508,23 +516,34 @@ class SettingsController extends GetxController { |
|
|
|
.tr //当前已是最新版本 |
|
|
|
.replaceAll('{version}', updateInfo.currentVersion), |
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
backgroundColor: Colors.green.withOpacity(0.8), |
|
|
|
backgroundColor: Colors.green.withValues(alpha: 0.8), |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
// 关闭加载提示 |
|
|
|
if (Get.isDialogOpen == true) { |
|
|
|
Get.back(); |
|
|
|
// 关闭加载提示 - 异常情况下的可靠关闭 |
|
|
|
if (dialogShown) { |
|
|
|
dialogShown = false; |
|
|
|
try { |
|
|
|
// 尝试直接关闭 |
|
|
|
Navigator.of(Get.overlayContext!).pop(); |
|
|
|
} catch (popError) { |
|
|
|
// 如果直接关闭失败,使用备用方案 |
|
|
|
if (Get.isDialogOpen == true) { |
|
|
|
Get.back(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Get.snackbar( |
|
|
|
'error'.tr, |
|
|
|
'networkErrorRetry'.tr, // 网络错误,请稍后重试 |
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
backgroundColor: Colors.red.withOpacity(0.8), |
|
|
|
backgroundColor: Colors.red.withValues(alpha: 0.8), |
|
|
|
colorText: Colors.white, |
|
|
|
); |
|
|
|
} finally { |
|
|
|
isCheckingUpdate = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|