Browse Source

feat(ota_check_service): 添加暗黑模式支持并改进对话框样式

为OTA检查服务的升级对话框添加暗黑模式适配,改进文本显示和样式配置。包括:
- 根据当前主题模式动态调整颜色
- 优化标题文本布局防止溢出
- 增强按钮边框和背景色适配
weicu
lxm 1 year ago
parent
commit
1001c83d02
  1. 43
      lib/data/services/ota_check_service.dart

43
lib/data/services/ota_check_service.dart

@ -47,7 +47,8 @@ class OtaCheckService extends GetxService {
/// 检查当前是否在Home页面 /// 检查当前是否在Home页面
bool _isCurrentlyOnHomePage() { bool _isCurrentlyOnHomePage() {
final currentRoute = Get.currentRoute; final currentRoute = Get.currentRoute;
final isOnHome = currentRoute == Routes.home || currentRoute == Routes.initial; final isOnHome =
currentRoute == Routes.home || currentRoute == Routes.initial;
Logger.d(_tag, '当前路由: $currentRoute, 是否在Home页面: $isOnHome'); Logger.d(_tag, '当前路由: $currentRoute, 是否在Home页面: $isOnHome');
return isOnHome; return isOnHome;
} }
@ -90,14 +91,16 @@ class OtaCheckService extends GetxService {
Logger.d(_tag, '当前版本: $currentVersion, 最新版本: $latestVersion'); Logger.d(_tag, '当前版本: $currentVersion, 最新版本: $latestVersion');
// 检查是否有更新 // 检查是否有更新
final hasUpdate = _otaCoreService.isNewVersionAvailable(currentVersion, latestVersion); final hasUpdate =
_otaCoreService.isNewVersionAvailable(currentVersion, latestVersion);
if (hasUpdate) { if (hasUpdate) {
Logger.d(_tag, '发现新版本,准备显示升级提醒'); Logger.d(_tag, '发现新版本,准备显示升级提醒');
// 再次确认当前在Home页面(防止异步执行期间页面切换) // 再次确认当前在Home页面(防止异步执行期间页面切换)
if (_isCurrentlyOnHomePage()) { if (_isCurrentlyOnHomePage()) {
_showOtaUpgradeDialog(latestVersion, latestInfo['updateDescription'] as String?); _showOtaUpgradeDialog(
latestVersion, latestInfo['updateDescription'] as String?);
} else { } else {
Logger.d(_tag, '检查完成时已不在Home页面,取消显示弹窗'); Logger.d(_tag, '检查完成时已不在Home页面,取消显示弹窗');
} }
@ -108,7 +111,6 @@ class OtaCheckService extends GetxService {
// 标记为已检查(无论是否有更新都标记为已检查) // 标记为已检查(无论是否有更新都标记为已检查)
_markAsChecked(); _markAsChecked();
return true; return true;
} catch (e) { } catch (e) {
Logger.e(_tag, '检查OTA升级失败: $e'); Logger.e(_tag, '检查OTA升级失败: $e');
// 即使检查失败,也标记为已检查,避免重复尝试 // 即使检查失败,也标记为已检查,避免重复尝试
@ -126,6 +128,7 @@ class OtaCheckService extends GetxService {
Logger.d(_tag, '显示弹窗时发现不在Home页面,取消显示'); Logger.d(_tag, '显示弹窗时发现不在Home页面,取消显示');
return; return;
} }
final isDarkMode = Get.isDarkMode;
Logger.d(_tag, '显示OTA升级提醒对话框'); Logger.d(_tag, '显示OTA升级提醒对话框');
@ -135,15 +138,22 @@ class OtaCheckService extends GetxService {
children: [ children: [
Icon( Icon(
Icons.headset, Icons.headset,
color: Colors.blue[600], color: isDarkMode ? const Color(0xFF0066CC) : Colors.blue[600],
size: 24.sp, size: 24.sp,
), ),
SizedBox(width: 8.w), SizedBox(width: 8.w),
Text( // 使用Flexible确保标题文本能够自适应不同语言长度,避免溢出
'ota_newVersionFound'.tr, Flexible(
style: TextStyle( child: Text(
color: Colors.blue[700], 'ota_newVersionFound'.tr, // 发现新版本
fontWeight: FontWeight.w600, style: TextStyle(
color: isDarkMode ? Colors.white : Colors.blue[700],
fontWeight: FontWeight.w600,
fontSize: 20.sp, // 设置合适的字体大小
),
softWrap: true, // 启用软换行
overflow: TextOverflow.visible, // 确保文本完全显示
maxLines: 2, // 最多显示两行
), ),
), ),
], ],
@ -155,6 +165,7 @@ class OtaCheckService extends GetxService {
Text( Text(
'${'latestFirmwareVersion'.tr}: $latestVersion', '${'latestFirmwareVersion'.tr}: $latestVersion',
style: TextStyle( style: TextStyle(
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
fontSize: 16.sp, fontSize: 16.sp,
), ),
@ -173,7 +184,9 @@ class OtaCheckService extends GetxService {
}, },
child: Text( child: Text(
'talkLater'.tr, 'talkLater'.tr,
style: TextStyle(color: Colors.grey[600]), style: TextStyle(
color: isDarkMode ? Colors.grey[400] : Colors.grey[600],
),
), ),
), ),
// 立即升级 (靠右) // 立即升级 (靠右)
@ -184,11 +197,15 @@ class OtaCheckService extends GetxService {
Get.toNamed(Routes.OTA_UPGRADE); Get.toNamed(Routes.OTA_UPGRADE);
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue[600], backgroundColor:
isDarkMode ? const Color(0xFF0066CC) : Colors.blue[600],
foregroundColor: Colors.white, foregroundColor: Colors.white,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.sp), borderRadius: BorderRadius.circular(8.sp),
), ),
side: isDarkMode
? BorderSide(color: Colors.grey[800]!, width: 1)
: BorderSide.none,
), ),
child: Text( child: Text(
'ota_updateNow'.tr, 'ota_updateNow'.tr,
@ -201,7 +218,7 @@ class OtaCheckService extends GetxService {
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12.sp), borderRadius: BorderRadius.circular(12.sp),
), ),
backgroundColor: Colors.white, backgroundColor: isDarkMode ? const Color(0xFF1A1A1A) : Colors.white,
), ),
barrierDismissible: true, // 允许点击外部关闭 barrierDismissible: true, // 允许点击外部关闭
); );

Loading…
Cancel
Save