From ec488f26d17f3081ec03c1df47ea12507237626d Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Mon, 18 Aug 2025 14:47:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AE=BE=E7=BD=AE):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF=E6=98=BE=E7=A4=BA=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E5=92=8C=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在VersionUpdateService中添加国家地区编码、语言编码和服务器地址的获取 - 在SettingsController中实现隐藏点击功能,可显示调试信息 - 在设置页面添加调试信息展示区域,显示应用版本和设备信息 --- lib/data/services/version_update_service.dart | 13 ++ .../controllers/settings_controller.dart | 68 ++++++- lib/modules/settings/views/settings_view.dart | 188 +++++++++++------- 3 files changed, 187 insertions(+), 82 deletions(-) diff --git a/lib/data/services/version_update_service.dart b/lib/data/services/version_update_service.dart index 4c408e107..e959227ce 100644 --- a/lib/data/services/version_update_service.dart +++ b/lib/data/services/version_update_service.dart @@ -27,6 +27,10 @@ class VersionUpdateService extends GetxService { static bool? _isShowTourists = false; //是否显示游客登录 static DateTime? _lastCheckTime; //上次检查时间 static const int _cacheIntervalMinutes = 10; // 可配置化 + static final String? _countryCode = Get.deviceLocale?.countryCode; //国家地区编码 + static final String? _languageCode = Get.deviceLocale?.languageCode; //语言编码 + // ignore: non_constant_identifier_names + static final String? _SERVER_URL = dotenv.env['SERVER_URL']; //服务器地址 // 添加 getter 方法来访问缓存的静态数据 /// 获取缓存的应用版本 @@ -62,6 +66,15 @@ class VersionUpdateService extends GetxService { /// 获取上次检查时间 DateTime? get lastCheckTime => _lastCheckTime; + /// 获取缓存的国家地区编码 + String get cachedCountryCode => _countryCode ?? ''; + + /// 获取缓存的语言编码 + String get cachedLanguageCode => _languageCode ?? ''; + + /// 获取缓存的服务器地址 + String get cachedServerUrl => _SERVER_URL ?? ''; + final Logger _logger = Logger(); /// 获取当前应用版本信息 diff --git a/lib/modules/settings/controllers/settings_controller.dart b/lib/modules/settings/controllers/settings_controller.dart index ffa5c1b64..372e664ca 100644 --- a/lib/modules/settings/controllers/settings_controller.dart +++ b/lib/modules/settings/controllers/settings_controller.dart @@ -1,18 +1,19 @@ +import 'dart:async'; + import 'package:agent_service/agent_service.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:dio/dio.dart'; import 'package:get_storage/get_storage.dart'; +import 'package:logger/logger.dart'; +import 'package:package_info_plus/package_info_plus.dart'; + import '../../../core/themes/theme_service.dart'; import '../../../data/services/speech_factory.dart'; import '../../../routes/app_routes.dart'; import '../models/language_model.dart'; -import 'package:logger/logger.dart'; import '../../../data/services/ble_manager.dart'; import '../../../data/services/language_manager.dart'; - -import 'package:package_info_plus/package_info_plus.dart'; -import 'dart:async'; import '../../../data/services/version_update_service.dart'; import '../../common/widgets/version_update_dialog.dart'; @@ -128,7 +129,10 @@ class SettingsController extends GetxController { bool isCheckingUpdate = false; //状态锁,防止重复检查 DateTime? lastCheckTime; // 添加上次检查时间记录 - + // 隐藏功能变量 + int _clickCount = 0; // 点击计数 + DateTime? _lastClickTime; // 上次点击时间 + final RxBool showDebugInfo = false.obs; // 是否显示调试信息 @override void onInit() { @@ -548,4 +552,58 @@ class SettingsController extends GetxController { isCheckingUpdate = false; } } + + /// 处理隐藏功能点击 + void handleSecretTap() { + final now = DateTime.now(); + + // 如果距离上次点击超过2秒,重置计数 + if (_lastClickTime != null && + now.difference(_lastClickTime!).inSeconds > 2) { + _clickCount = 0; + } + + _lastClickTime = now; + _clickCount++; + + // 点击5次后显示版本信息 + if (_clickCount >= 5) { + showDebugInfo.value = !showDebugInfo.value; + _clickCount = 0; + + // Get.snackbar( + // showDebugInfo.value ? '调试信息已显示' : '调试信息已隐藏', + // '版本服务数据', + // snackPosition: SnackPosition.TOP, + // backgroundColor: Colors.blue.withOpacity(0.8), + // colorText: Colors.white, + // duration: const Duration(seconds: 1), + // ); + } + } + + /// 获取当前应用数据 + String getSomeAppData() { + try { + final versionService = Get.find(); + return ''' +应用版本: ${versionService.cachedAppVersion} +构建号: ${versionService.cachedBuildNumber} +平台: ${versionService.cachedPlatform} +设备品牌: ${versionService.cachedDeviceBrand} +渠道: ${versionService.cachedChannel} +最新版本: ${versionService.cachedLatestVersion} +有更新: ${versionService.cachedHasUpdate} +强制更新: ${versionService.cachedIsForceUpdate} +更新链接: ${versionService.cachedUpdateUrl} +游客模式: ${versionService.cachedShowTourists} +最近版本检查时间: ${versionService.lastCheckTime ?? '未检查'} +国家地区编码: ${versionService.cachedCountryCode} +语言编码: ${versionService.cachedLanguageCode} +服务器地址: ${versionService.cachedServerUrl} +'''; + } catch (e) { + return '获取版本服务数据失败: $e'; + } + } } diff --git a/lib/modules/settings/views/settings_view.dart b/lib/modules/settings/views/settings_view.dart index 47d859ba3..4220460bd 100644 --- a/lib/modules/settings/views/settings_view.dart +++ b/lib/modules/settings/views/settings_view.dart @@ -657,18 +657,19 @@ class SettingsView extends GetView { ), ], ), - child: ClipRRect( - borderRadius: BorderRadius.circular(16.r), - child: BackdropFilter( - filter: isDarkMode - ? ImageFilter.blur(sigmaX: 5, sigmaY: 5) - : ImageFilter.blur(sigmaX: 0, sigmaY: 0), - child: Row( - children: [ - // 左侧应用信息区域 - 使用固定宽度 - Row( - children: [ - Container( + clipBehavior: Clip.antiAlias, + child: BackdropFilter( + filter: isDarkMode + ? ImageFilter.blur(sigmaX: 5, sigmaY: 5) + : ImageFilter.blur(sigmaX: 0, sigmaY: 0), + child: Row( + children: [ + // 左侧应用信息区域 - 使用固定宽度 + Row( + children: [ + GestureDetector( + onTap: controller.handleSecretTap, // 点击事件 + child: Container( width: 40.w, height: 40.w, decoration: BoxDecoration( @@ -690,82 +691,82 @@ class SettingsView extends GetView { color: Colors.white, ), ), - SizedBox(width: 12.w), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - 'Voitrans', - style: TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.w500, - color: isDarkMode ? Colors.white : Colors.black87, - ), + ), + SizedBox(width: 12.w), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + 'Voitrans', + style: TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.w500, + color: isDarkMode ? Colors.white : Colors.black87, ), - SizedBox(height: 2.h), - Obx(() => Text( - // 如果版本信息为空,显示加载中 - controller.appVersion.value.isEmpty - ? '${'versions'.tr} ${'loading'.tr}' // 版本 加载中 - : '${'versions'.tr} ${controller.appVersion.value} (Build ${controller.buildNumber.value})', // 版本号 - style: TextStyle( - fontSize: 12.sp, - color: isDarkMode - ? Colors.white70 - : Colors.black54, - ), - )), - ], - ), - ], - ), - - // 间距 - SizedBox(width: 16.w), - - // 右侧检查更新按钮 - 使用Expanded确保充分利用剩余空间 - Expanded( - child: InkWell( - onTap: () { - // 调用检查更新方法 - controller.checkForUpdate(); - }, - child: Container( - constraints: BoxConstraints( - minHeight: 36.h, // 设置最小高度而不是宽度约束 - ), - padding: EdgeInsets.symmetric( - horizontal: 12.w, - vertical: 8.h, - ), - decoration: BoxDecoration( - color: isDarkMode - ? Colors.blue[900]!.withOpacity(0.3) - : Colors.blue[100], - borderRadius: BorderRadius.circular(16.r), ), - child: Center( - child: FittedBox( - fit: BoxFit.scaleDown, // 如果文本过长,自动缩小字体 - child: Text( - 'checkUpdates'.tr, // 检查更新 + SizedBox(height: 2.h), + Obx(() => Text( + // 如果版本信息为空,显示加载中 + controller.appVersion.value.isEmpty + ? '${'versions'.tr} ${'loading'.tr}' // 版本 加载中 + : '${'versions'.tr} ${controller.appVersion.value} (Build ${controller.buildNumber.value})', // 版本号 style: TextStyle( fontSize: 12.sp, color: isDarkMode - ? Colors.blue[300] - : Colors.blue[600], - height: 1.2, // 稍微减少行高,适应FittedBox + ? Colors.white70 + : Colors.black54, ), - textAlign: TextAlign.center, - maxLines: 2, // 最多显示2行,配合FittedBox使用 + )), + ], + ), + ], + ), + + // 间距 + SizedBox(width: 16.w), + + // 右侧检查更新按钮 - 使用Expanded确保充分利用剩余空间 + Expanded( + child: InkWell( + onTap: () { + // 调用检查更新方法 + controller.checkForUpdate(); + }, + child: Container( + constraints: BoxConstraints( + minHeight: 36.h, // 设置最小高度而不是宽度约束 + ), + padding: EdgeInsets.symmetric( + horizontal: 12.w, + vertical: 8.h, + ), + decoration: BoxDecoration( + color: isDarkMode + ? Colors.blue[900]!.withOpacity(0.3) + : Colors.blue[100], + borderRadius: BorderRadius.circular(16.r), + ), + child: Center( + child: FittedBox( + fit: BoxFit.scaleDown, // 如果文本过长,自动缩小字体 + child: Text( + 'checkUpdates'.tr, // 检查更新 + style: TextStyle( + fontSize: 12.sp, + color: isDarkMode + ? Colors.blue[300] + : Colors.blue[600], + height: 1.2, // 稍微减少行高,适应FittedBox ), + textAlign: TextAlign.center, + maxLines: 2, // 最多显示2行,配合FittedBox使用 ), ), ), ), ), - ], - ), + ), + ], ), ), ), @@ -793,7 +794,7 @@ class SettingsView extends GetView { Get.locale?.countryCode == 'CN') InkWell( onTap: () => Get.to( - () => WebViewPage( + () => const WebViewPage( url: 'https://beian.miit.gov.cn', title: 'ICP备案信息', ), @@ -809,6 +810,39 @@ class SettingsView extends GetView { ], ), ), + // 隐藏的调试信息 + Obx(() => controller.showDebugInfo.value + ? Container( + margin: EdgeInsets.only(top: 12.h), + padding: EdgeInsets.all(12.w), + decoration: BoxDecoration( + color: isDarkMode ? Colors.grey[800] : Colors.grey[100], + borderRadius: BorderRadius.circular(8.r), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '版本服务调试信息', + style: TextStyle( + fontSize: 12.sp, + fontWeight: FontWeight.bold, + color: isDarkMode ? Colors.white : Colors.black, + ), + ), + SizedBox(height: 8.h), + Text( + controller.getSomeAppData(), + style: TextStyle( + fontSize: 10.sp, + fontFamily: 'monospace', + color: isDarkMode ? Colors.white70 : Colors.black87, + ), + ), + ], + ), + ) + : const SizedBox.shrink()), ], ); }