diff --git a/lib/app/common/app_config.dart b/lib/app/common/app_config.dart index 6e00c07..2b543d1 100755 --- a/lib/app/common/app_config.dart +++ b/lib/app/common/app_config.dart @@ -1255,7 +1255,7 @@ class AppConfig { /// 建议: /// - 测试版本、Beta 版本:设置为 true /// - 正式生产版本:根据需要设置为 false(或在遇到问题时临时开启) - static const bool enableInitLogCollection = true; + static const bool enableInitLogCollection = false; /// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ /// 加密密钥配置 diff --git a/lib/app/modules/kr_home/controllers/kr_home_controller.dart b/lib/app/modules/kr_home/controllers/kr_home_controller.dart index 5792065..51b2454 100755 --- a/lib/app/modules/kr_home/controllers/kr_home_controller.dart +++ b/lib/app/modules/kr_home/controllers/kr_home_controller.dart @@ -528,8 +528,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { // 添加更详细的状态监听 ever(KRSingBoxImp.instance.kr_status, (status) { if (kDebugMode) { - print('🔵 Controller 收到状态变化: ${status.runtimeType}'); - } + } KRLogUtil.kr_i('🔄 连接状态变化: $status', tag: 'HomeController'); KRLogUtil.kr_i('📊 当前状态类型: ${status.runtimeType}', tag: 'HomeController'); @@ -558,8 +557,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { case SingboxStarted(): KRLogUtil.kr_i('🟢 状态: 已启动', tag: 'HomeController'); if (kDebugMode) { - print('🔵 状态变为 Started, 当前延迟=${kr_currentNodeLatency.value}'); - } + } // 取消连接超时处理 _cancelConnectionTimeout(); @@ -572,13 +570,11 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { // 🔧 关键修复:如果延迟还是-1(连接中状态),立即设置为0(已连接但延迟未知) if (kr_currentNodeLatency.value == -1) { if (kDebugMode) { - print('🔵 强制将延迟从 -1 更新为 0'); - } + } kr_currentNodeLatency.value = 0; kr_currentNodeLatency.refresh(); // 强制刷新延迟值 if (kDebugMode) { - print('🔵 延迟值已刷新'); - } + } } // 🔧 修复:立即尝试更新延迟值 @@ -589,8 +585,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { // 强制更新UI update(); if (kDebugMode) { - print('🔵 状态更新完成,当前延迟=${kr_currentNodeLatency.value}'); - } + } break; case SingboxStopping(): KRLogUtil.kr_i('🟠 状态: 正在停止', tag: 'HomeController'); @@ -677,15 +672,13 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { KRLogUtil.kr_i('🔵 toggleSwitch 被调用: value=$value, currentStatus=$currentStatus', tag: 'HomeController'); if (kDebugMode) { - print('🔵 toggleSwitch: value=$value, currentStatus=$currentStatus'); - } + } // 🔧 关键: 如果正在切换中,直接忽略(参考 hiddify-app 的 "switching status, debounce") if (currentStatus is SingboxStarting || currentStatus is SingboxStopping) { KRLogUtil.kr_i('🔄 正在切换中,忽略本次操作 (当前状态: $currentStatus)', tag: 'HomeController'); if (kDebugMode) { - print('🔵 忽略操作:正在切换中'); - } + } return; } @@ -694,13 +687,11 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { // 开启连接 KRLogUtil.kr_i('🔄 开始连接...', tag: 'HomeController'); if (kDebugMode) { - print('🔵 执行 kr_start()'); - } + } await KRSingBoxImp.instance.kr_start(); KRLogUtil.kr_i('✅ 连接命令已发送', tag: 'HomeController'); if (kDebugMode) { - print('🔵 kr_start() 完成'); - } + } // 🔧 修复: 等待状态更新,最多3秒 await _waitForStatus(SingboxStarted, maxSeconds: 3); @@ -708,8 +699,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { // 关闭连接 KRLogUtil.kr_i('🛑 开始断开连接...', tag: 'HomeController'); if (kDebugMode) { - print('🔵 执行 kr_stop()'); - } + } await KRSingBoxImp.instance.kr_stop().timeout( const Duration(seconds: 10), onTimeout: () { @@ -719,8 +709,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { ); KRLogUtil.kr_i('✅ 断开命令已发送', tag: 'HomeController'); if (kDebugMode) { - print('🔵 kr_stop() 完成'); - } + } // 🔧 修复: 等待状态更新,最多2秒 await _waitForStatus(SingboxStopped, maxSeconds: 2); @@ -728,34 +717,29 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { } catch (e) { KRLogUtil.kr_e('❌ 切换失败: $e', tag: 'HomeController'); if (kDebugMode) { - print('🔵 切换失败: $e'); - } + } // 发生错误时强制同步状态 kr_forceSyncConnectionStatus(); } if (kDebugMode) { - print('🔵 toggleSwitch 完成,当前 kr_isConnected=${kr_isConnected.value}'); - } + } } /// 🔧 等待状态达到预期值 Future _waitForStatus(Type expectedType, {int maxSeconds = 3}) async { if (kDebugMode) { - print('🔵 等待状态变为: $expectedType'); - } + } final startTime = DateTime.now(); while (DateTime.now().difference(startTime).inSeconds < maxSeconds) { final currentStatus = KRSingBoxImp.instance.kr_status.value; if (kDebugMode) { - print('🔵 当前状态: ${currentStatus.runtimeType}'); - } + } if (currentStatus.runtimeType == expectedType) { if (kDebugMode) { - print('🔵 状态已达到: $expectedType'); - } + } // 强制同步确保 kr_isConnected 正确 kr_forceSyncConnectionStatus(); return; @@ -765,8 +749,7 @@ class KRHomeController extends GetxController with WidgetsBindingObserver { } if (kDebugMode) { - print('🔵 等待超时,强制同步状态'); - } + } kr_forceSyncConnectionStatus(); } diff --git a/lib/app/modules/kr_home/views/kr_home_bottom_panel.dart b/lib/app/modules/kr_home/views/kr_home_bottom_panel.dart index b58c959..82781c8 100755 --- a/lib/app/modules/kr_home/views/kr_home_bottom_panel.dart +++ b/lib/app/modules/kr_home/views/kr_home_bottom_panel.dart @@ -12,8 +12,6 @@ import '../widgets/kr_subscription_card.dart'; import 'kr_home_trial_card.dart'; import 'kr_home_last_day_card.dart'; import '../../../utils/kr_log_util.dart'; -import 'dart:io'; -import 'package:path_provider/path_provider.dart'; class KRHomeBottomPanel extends GetView { const KRHomeBottomPanel({super.key}); @@ -109,25 +107,6 @@ class KRHomeBottomPanel extends GetView { Builder(builder: (context) { KRLogUtil.kr_i('🔹 渲染订阅卡片,margin: top=${12}, left=${12}, right=${12}', tag: 'HomeBottomPanel'); - // 🔧 紧急诊断:异步写文件确认订阅卡片被渲染(不阻塞UI) - Future.microtask(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/SUBSCRIPTION_CARD_RENDER_DEBUG.txt'); - await debugFile.writeAsString( - '=' * 60 + '\n' - '🔹 订阅卡片正在渲染!\n' - '时间: ${DateTime.now()}\n' - '版本标识: Android15_Fix_v6_Final\n' - '=' * 60 + '\n', - mode: FileMode.append, - ); - print('🔹 [BottomPanel] ✅ 订阅卡片渲染日志已写入文件: ${debugFile.path}'); - } catch (e) { - print('🔹 [BottomPanel] ❌ 写入订阅卡片渲染日志失败: $e'); - } - }); - return Container( margin: EdgeInsets.only(top: 12, left: 12, right: 12), child: const KRSubscriptionCard(), diff --git a/lib/app/modules/kr_home/views/kr_home_node_list_view.dart b/lib/app/modules/kr_home/views/kr_home_node_list_view.dart index e6a2e71..35da75f 100755 --- a/lib/app/modules/kr_home/views/kr_home_node_list_view.dart +++ b/lib/app/modules/kr_home/views/kr_home_node_list_view.dart @@ -1,7 +1,6 @@ import 'dart:math'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:kaer_with_panels/app/localization/app_translations.dart'; import 'package:kaer_with_panels/app/widgets/kr_app_text_style.dart'; import 'package:kaer_with_panels/app/widgets/kr_country_flag.dart'; @@ -71,20 +70,20 @@ class KRHomeNodeListView extends GetView { /// 构建专用服务器列表 Widget _buildServerList(BuildContext context) { return Container( - width: ScreenUtil().screenWidth, - height: 360.h, // 减小高度比例 + width: MediaQuery.of(context).size.width, + height: 360, // 减小高度比例 decoration: BoxDecoration( color: Theme.of(context).primaryColor, borderRadius: BorderRadius.only( - topLeft: Radius.circular(20.w), - topRight: Radius.circular(20.w), + topLeft: Radius.circular(20), + topRight: Radius.circular(20), ), ), child: Column( children: [ // 标题栏 Padding( - padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h), + padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -103,7 +102,7 @@ class KRHomeNodeListView extends GetView { }, child: Icon( Icons.close, - size: 24.w, + size: 24, color: Theme.of(context).textTheme.bodyMedium?.color, ), ), @@ -125,19 +124,19 @@ class KRHomeNodeListView extends GetView { ); } return ListView.builder( - padding: EdgeInsets.symmetric(horizontal: 16.w), + padding: EdgeInsets.symmetric(horizontal: 16), itemCount: controller.kr_subscribeService.groupOutboundList.length, itemBuilder: (context, index) { final group = controller.kr_subscribeService.groupOutboundList[index]; return Container( - margin: EdgeInsets.only(bottom: 8.w), + margin: EdgeInsets.only(bottom: 8), decoration: BoxDecoration( color: Theme.of(context).cardColor, - borderRadius: BorderRadius.circular(12.w), + borderRadius: BorderRadius.circular(12), border: Border.all( color: Theme.of(context).dividerColor.withOpacity(0.1), - width: 1.w, + width: 1, ), ), child: InkWell( @@ -146,18 +145,18 @@ class KRHomeNodeListView extends GetView { controller.kr_currentListStatus.value = KRHomeViewsListStatus.kr_serverSubscribeList; }, - borderRadius: BorderRadius.circular(12.w), + borderRadius: BorderRadius.circular(12), child: Padding( - padding: EdgeInsets.all(12.w), + padding: EdgeInsets.all(12), child: Row( children: [ KRNetworkImage( kr_imageUrl: group.icon, - kr_width: 32.w, - kr_height: 32.w, + kr_width: 32, + kr_height: 32, kr_fit: BoxFit.cover, ), - SizedBox(width: 12.w), + SizedBox(width: 12), Expanded( child: Text( group.tag, @@ -171,7 +170,7 @@ class KRHomeNodeListView extends GetView { ), Icon( Icons.arrow_forward_ios, - size: 16.w, + size: 16, color: Theme.of(context).textTheme.bodySmall?.color, ), ], @@ -208,7 +207,7 @@ class KRHomeNodeListView extends GetView { return _kr_buildListContainer( context, child: ListView.builder( - padding: EdgeInsets.fromLTRB(16.w, 8.w, 16.w, 0), + padding: EdgeInsets.fromLTRB(16, 8, 16, 0), itemCount: controller.kr_subscribeService.countryOutboundList.length, itemBuilder: (context, index) { @@ -222,15 +221,15 @@ class KRHomeNodeListView extends GetView { country.isExpand.value = !country.isExpand.value; }, child: Container( - padding: EdgeInsets.symmetric(vertical: 12.h), + padding: EdgeInsets.symmetric(vertical: 12), child: Row( children: [ KRCountryFlag( countryCode: country.country, - width: 40.w, - height: 40.w, + width: 40, + height: 40, ), - SizedBox(width: 12.w), + SizedBox(width: 12), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -255,7 +254,7 @@ class KRHomeNodeListView extends GetView { country.isExpand.value ? Icons.keyboard_arrow_down : Icons.arrow_forward_ios, - size: 16.w, + size: 16, color: Theme.of(context).textTheme.bodySmall?.color, ); @@ -272,7 +271,7 @@ class KRHomeNodeListView extends GetView { return ListView.builder( shrinkWrap: true, physics: NeverScrollableScrollPhysics(), - padding: EdgeInsets.only(left: 24.w), + padding: EdgeInsets.only(left: 24), itemCount: country.outboundList.length, itemBuilder: (context, index) { final server = country.outboundList[index]; @@ -311,13 +310,13 @@ class KRHomeNodeListView extends GetView { }, child: Container( padding: EdgeInsets.symmetric( - vertical: 8.h, - horizontal: 16.w, + vertical: 8, + horizontal: 16, ), decoration: BoxDecoration( // 添加轻微的背景色以区分点击区域 color: Theme.of(context).cardColor, - borderRadius: BorderRadius.circular(8.w), + borderRadius: BorderRadius.circular(8), ), child: _kr_buildNodeListItem( context, @@ -328,9 +327,9 @@ class KRHomeNodeListView extends GetView { // 添加分隔线 if (index < country.outboundList.length - 1) Divider( - height: 1.w, - indent: 16.w, - endIndent: 16.w, + height: 1, + indent: 16, + endIndent: 16, color: Theme.of(context) .dividerColor .withOpacity(0.1), @@ -341,7 +340,7 @@ class KRHomeNodeListView extends GetView { ); }), Divider( - height: 1.w, + height: 1, color: Theme.of(context).dividerColor.withOpacity(0.1), ), ], @@ -377,7 +376,7 @@ class KRHomeNodeListView extends GetView { return _kr_buildListContainer( context, child: ListView.builder( - padding: EdgeInsets.fromLTRB(16.w, 16.w, 16.w, 0), + padding: EdgeInsets.fromLTRB(16, 16, 16, 0), itemCount: servers.length, itemBuilder: (context, index) { final server = servers[index]; @@ -406,7 +405,7 @@ class KRHomeNodeListView extends GetView { } }, child: Container( - padding: EdgeInsets.symmetric(vertical: 4.h), + padding: EdgeInsets.symmetric(vertical: 4), child: _kr_buildNodeListItem( context, item: server, @@ -415,7 +414,7 @@ class KRHomeNodeListView extends GetView { ), if (index < servers.length - 1) Divider( - height: 1.w, + height: 1, color: Theme.of(context).dividerColor.withOpacity(0.1), ), ], @@ -435,12 +434,12 @@ class KRHomeNodeListView extends GetView { required Widget listContent, }) { return Container( - width: ScreenUtil().screenWidth, + width: MediaQuery.of(context).size.width, decoration: BoxDecoration( color: Theme.of(context).primaryColor, borderRadius: BorderRadius.only( - topLeft: Radius.circular(20.w), - topRight: Radius.circular(20.w), + topLeft: Radius.circular(20), + topRight: Radius.circular(20), ), ), child: Column( @@ -453,13 +452,13 @@ class KRHomeNodeListView extends GetView { onClose: () => controller.kr_currentListStatus.value = KRHomeViewsListStatus.kr_none, ), - SizedBox(height: 16.h), + SizedBox(height: 16), Expanded( child: Column( children: [ Expanded(child: listContent), // 添加底部间距 - SizedBox(height: 12.h), + SizedBox(height: 12), ], ), ), @@ -476,7 +475,7 @@ class KRHomeNodeListView extends GetView { VoidCallback? onClose, }) { return Padding( - padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 16.w), + padding: EdgeInsets.only(left: 16, right: 16, top: 16), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -487,11 +486,11 @@ class KRHomeNodeListView extends GetView { onTap: onBack, child: Icon( Icons.arrow_back_ios, - size: 20.w, + size: 20, color: Theme.of(context).textTheme.bodyMedium?.color, ), ), - SizedBox(width: 8.w), + SizedBox(width: 8), ], Text( title, @@ -508,7 +507,7 @@ class KRHomeNodeListView extends GetView { onTap: onClose, child: Icon( Icons.close, - size: 24.w, + size: 24, color: Theme.of(context).textTheme.bodyMedium?.color, ), ), @@ -524,10 +523,10 @@ class KRHomeNodeListView extends GetView { required Widget child, }) { return Container( - margin: EdgeInsets.symmetric(horizontal: 16.w), + margin: EdgeInsets.symmetric(horizontal: 16), decoration: BoxDecoration( color: Theme.of(context).cardColor, - borderRadius: BorderRadius.circular(12.w), + borderRadius: BorderRadius.circular(12), ), child: child, ); @@ -553,17 +552,17 @@ class KRHomeNodeListView extends GetView { return Container( key: ValueKey(item.id), - padding: EdgeInsets.symmetric(vertical: 8.h), + padding: EdgeInsets.symmetric(vertical: 8), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ // 🔧 修改:显示国旗代替图标 KRCountryFlag( countryCode: item.country, - width: 36.w, - height: 36.w, + width: 36, + height: 36, ), - SizedBox(width: 8.w), + SizedBox(width: 8), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -582,12 +581,12 @@ class KRHomeNodeListView extends GetView { Obx( () => controller.kr_cutTag.value == item.tag ? Container( - margin: EdgeInsets.only(left: 4.w), + margin: EdgeInsets.only(left: 4), padding: EdgeInsets.symmetric( - horizontal: 4.w, vertical: 1.h), + horizontal: 4, vertical: 1), decoration: BoxDecoration( color: krModernGreenLight.withOpacity(0.1), - borderRadius: BorderRadius.circular(4.w), + borderRadius: BorderRadius.circular(4), ), child: Text( AppTranslations.kr_home.selected, @@ -602,7 +601,7 @@ class KRHomeNodeListView extends GetView { ), ], ), - SizedBox(height: 2.h), + SizedBox(height: 2), Text( item.city, style: KrAppTextStyle( @@ -669,20 +668,20 @@ class KRHomeNodeListView extends GetView { return _kr_buildListContainer( context, child: ListView( - padding: EdgeInsets.fromLTRB(16.w, 0, 16.w, 0), + padding: EdgeInsets.fromLTRB(16, 0, 16, 0), children: [ // 延迟测试按钮作为第一个列表项 InkWell( onTap: () => controller.kr_urlTest(), child: Container( - padding: EdgeInsets.symmetric(vertical: 8.h), - margin: EdgeInsets.only(top: 8.w), // 添加上方间距 + padding: EdgeInsets.symmetric(vertical: 8), + margin: EdgeInsets.only(top: 8), // 添加上方间距 child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( - width: 36.w, - height: 36.w, + width: 36, + height: 36, decoration: BoxDecoration( color: krModernGreenLight.withOpacity(0.1), shape: BoxShape.circle, @@ -691,17 +690,17 @@ class KRHomeNodeListView extends GetView { child: controller.kr_isLatency.value ? KRSimpleLoading( color: krModernGreen, - size: 24.w, + size: 24, duration: const Duration(milliseconds: 800), ) : Icon( Icons.speed, - size: 24.w, + size: 24, color: krModernGreen, ), ), ), - SizedBox(width: 8.w), + SizedBox(width: 8), Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -728,7 +727,7 @@ class KRHomeNodeListView extends GetView { ), ), if (!controller.kr_isLatency.value) ...[ - SizedBox(height: 2.h), + SizedBox(height: 2), Text( AppTranslations.kr_home.refreshLatencyDesc, style: KrAppTextStyle( @@ -746,7 +745,7 @@ class KRHomeNodeListView extends GetView { if (!controller.kr_isLatency.value) Icon( Icons.arrow_forward_ios, - size: 12.w, + size: 12, color: Theme.of(context).textTheme.bodySmall?.color, ), ], @@ -755,7 +754,7 @@ class KRHomeNodeListView extends GetView { ), // 分隔线 Divider( - height: 16.w, + height: 16, color: Theme.of(context).dividerColor.withOpacity(0.1), ), // Auto 选项 @@ -775,19 +774,19 @@ class KRHomeNodeListView extends GetView { } }, child: Container( - padding: EdgeInsets.symmetric(vertical: 8.h), + padding: EdgeInsets.symmetric(vertical: 8), child: Row( crossAxisAlignment: CrossAxisAlignment.center, children: [ KrLocalImage( imageName: "home_list_location", - width: 36.w, - height: 36.w, + width: 36, + height: 36, color: controller.kr_cutTag.value == 'auto' ? Colors.green : null, ), - SizedBox(width: 8.w), + SizedBox(width: 8), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, @@ -808,13 +807,13 @@ class KRHomeNodeListView extends GetView { ), if (controller.kr_cutTag.value == 'auto') Container( - margin: EdgeInsets.only(left: 4.w), + margin: EdgeInsets.only(left: 4), padding: EdgeInsets.symmetric( - horizontal: 4.w, vertical: 1.h), + horizontal: 4, vertical: 1), decoration: BoxDecoration( color: krModernGreenLight.withOpacity(0.1), - borderRadius: BorderRadius.circular(4.w), + borderRadius: BorderRadius.circular(4), ), child: Text( AppTranslations.kr_home.selected, @@ -827,7 +826,7 @@ class KRHomeNodeListView extends GetView { ), ], ), - SizedBox(height: 2.h), + SizedBox(height: 2), Obx(() { // 获取当前自动选择的节点 String selectedNode = @@ -903,7 +902,7 @@ class KRHomeNodeListView extends GetView { ), // 分隔线 Divider( - height: 16.w, + height: 16, color: Theme.of(context).dividerColor.withOpacity(0.1), ), // 节点列表 @@ -929,7 +928,7 @@ class KRHomeNodeListView extends GetView { } }, child: Container( - padding: EdgeInsets.symmetric(vertical: 4.h), + padding: EdgeInsets.symmetric(vertical: 4), child: _kr_buildNodeListItem( context, item: node, @@ -939,7 +938,7 @@ class KRHomeNodeListView extends GetView { if (node != controller.kr_subscribeService.allList.last) Divider( - height: 1.w, + height: 1, color: Theme.of(context) .dividerColor .withOpacity(0.1), diff --git a/lib/app/modules/kr_home/widgets/kr_subscription_card.dart b/lib/app/modules/kr_home/widgets/kr_subscription_card.dart index 5a8b091..c72e300 100755 --- a/lib/app/modules/kr_home/widgets/kr_subscription_card.dart +++ b/lib/app/modules/kr_home/widgets/kr_subscription_card.dart @@ -1,12 +1,8 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:kaer_with_panels/app/localization/app_translations.dart'; -import 'dart:io'; -import 'package:path_provider/path_provider.dart'; - import 'package:kaer_with_panels/app/routes/app_pages.dart'; import 'package:kaer_with_panels/app/utils/kr_subscribe_navigation_util.dart'; - import '../../../widgets/kr_app_text_style.dart'; /// 订阅卡片组件 @@ -25,12 +21,6 @@ class KRSubscriptionCard extends StatelessWidget { // 构建订阅卡片 Widget _kr_buildSubscriptionCard(BuildContext context) { - // 🔧 新增:订阅卡片渲染日志 - print('🎴 [SubscriptionCard] 开始构建订阅卡片'); - print('🎴 [SubscriptionCard] 卡片颜色: ${Theme.of(context).cardColor}'); - print('🎴 [SubscriptionCard] 主题亮度: ${Theme.of(context).brightness}'); - print('🎴 [SubscriptionCard] 文本颜色: ${Theme.of(context).textTheme.bodyMedium?.color}'); - // 🔧 关键修复:完全移除 ScreenUtil,使用固定像素值避免缩放问题 return Container( // 添加固定高度,确保卡片可见 @@ -82,36 +72,7 @@ class KRSubscriptionCard extends StatelessWidget { height: 46, child: ElevatedButton( onPressed: () { - print('🎴 [SubscriptionCard] ========== 订阅按钮被点击 =========='); - print('🎴 [SubscriptionCard] 当前时间: ${DateTime.now()}'); - print('🎴 [SubscriptionCard] 准备调用导航方法...'); - - // 🔧 关键修复:文件写入改为非阻塞,不影响主流程 - Future(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/SUBSCRIBE_BUTTON_DEBUG.txt'); - await debugFile.writeAsString( - '=' * 60 + '\n' - '🎴 订阅按钮被点击!\n' - '时间: ${DateTime.now()}\n' - '版本标识: Android15_Fix_v6_Final\n' - '=' * 60 + '\n', - mode: FileMode.append, - ); - print('🎴 [SubscriptionCard] ✅ 按钮点击日志已写入文件: ${debugFile.path}'); - } catch (e) { - print('🎴 [SubscriptionCard] ❌ 写入按钮点击日志失败: $e'); - } - }); - - try { - KRSubscribeNavigationUtil.navigateToPurchase(tag: 'SubscriptionCard'); - print('🎴 [SubscriptionCard] 导航方法调用成功'); - } catch (e, stackTrace) { - print('🎴 [SubscriptionCard] ❌ 导航方法调用失败: $e'); - print('🎴 [SubscriptionCard] StackTrace: $stackTrace'); - } + KRSubscribeNavigationUtil.navigateToPurchase(tag: 'SubscriptionCard'); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.blue, diff --git a/lib/app/utils/kr_subscribe_navigation_util.dart b/lib/app/utils/kr_subscribe_navigation_util.dart index 689fafa..6c2b0b2 100644 --- a/lib/app/utils/kr_subscribe_navigation_util.dart +++ b/lib/app/utils/kr_subscribe_navigation_util.dart @@ -4,8 +4,6 @@ import 'package:kaer_with_panels/app/widgets/dialogs/kr_dialog.dart'; import 'package:kaer_with_panels/app/routes/app_pages.dart'; import 'package:kaer_with_panels/app/utils/kr_log_util.dart'; import 'package:kaer_with_panels/app/localization/app_translations.dart'; -import 'dart:io'; -import 'package:path_provider/path_provider.dart'; /// 订阅导航工具类 /// 用于统一处理订阅相关的导航逻辑 @@ -16,143 +14,38 @@ class KRSubscribeNavigationUtil { /// /// [tag] 调用来源标签,用于日志记录 static void navigateToPurchase({String tag = 'Subscribe'}) { - print('🔔 [NavigationUtil] ========== navigateToPurchase 被调用 =========='); - print('🔔 [NavigationUtil] Tag: $tag'); - print('🔔 [NavigationUtil] 当前时间: ${DateTime.now()}'); - - // 🔧 先获取关键信息并打印 final appRunData = KRAppRunData.getInstance(); final isDeviceLogin = appRunData.isDeviceLogin(); final account = appRunData.kr_account.value; - print('🔔 [NavigationUtil] 账号: $account'); - print('🔔 [NavigationUtil] 是否设备登录: $isDeviceLogin'); - KRLogUtil.kr_i('=== 订阅按钮点击 ===', tag: tag); KRLogUtil.kr_i('账号: $account', tag: tag); KRLogUtil.kr_i('是否设备登录: $isDeviceLogin', tag: tag); - // 🔧 文件写入改为非阻塞,放在后面 - Future(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/NAVIGATION_DEBUG.txt'); - await debugFile.writeAsString( - '=' * 60 + '\n' - '🔔 navigateToPurchase 被调用!\n' - '时间: ${DateTime.now()}\n' - '来源: $tag\n' - '账号: $account\n' - '是否设备登录: $isDeviceLogin\n' - '版本标识: Android15_Fix_v7_DialogFixed\n' - '=' * 60 + '\n', - mode: FileMode.append, - ); - } catch (e) { - print('🔔 [NavigationUtil] ❌ 写入导航日志失败: $e'); - } - }); - - // 🔧 v7 关键修复:恢复业务逻辑 - 设备登录用户必须先看到绑定提示对话框 - // v6 版本试图跳过对话框直接购买,但用户明确要求必须提示登录 - // 已修复 KRDialog 的 ScreenUtil 问题,对话框现在应该可以正常显示 - if (isDeviceLogin) { // 设备登录用户 - 显示绑定账号提示对话框 - print('🔔 [NavigationUtil] ⚠️ 检测到设备登录,显示绑定账号提示对话框'); KRLogUtil.kr_i('设备登录用户,显示绑定提示', tag: tag); - Future(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/NAVIGATION_DEBUG.txt'); - await debugFile.writeAsString( - '⚠️ 检测到设备登录,准备显示对话框\n' - '账号: $account\n' - '时间: ${DateTime.now()}\n' - '版本标识: Android15_Fix_v7_DialogFixed\n' - '-' * 60 + '\n', - mode: FileMode.append, - ); - } catch (e) { /* 忽略 */ } - }); - try { - print('🔔 [NavigationUtil] 📍 正在调用 KRDialog.show() 显示绑定提示...'); KRDialog.show( title: AppTranslations.kr_dialog.deviceLoginBindingTitle, message: AppTranslations.kr_dialog.deviceLoginBindingMessage, confirmText: AppTranslations.kr_dialog.kr_ok, onConfirm: () { - print('🔔 [NavigationUtil] 用户点击确认,跳转到登录页面'); Get.toNamed(Routes.MR_LOGIN); }, ); - print('🔔 [NavigationUtil] 📍 KRDialog.show() 调用完成'); } catch (e) { KRLogUtil.kr_e('显示绑定提示对话框失败: $e', tag: tag); - print('🔔 [NavigationUtil] ❌ 显示对话框异常: $e'); } } else { // 普通登录用户 - 直接跳转到购买页面 - print('🔔 [NavigationUtil] ✅ 普通用户,准备跳转到购买页面'); KRLogUtil.kr_i('普通用户,跳转到购买页面', tag: tag); - Future(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/NAVIGATION_DEBUG.txt'); - await debugFile.writeAsString( - '✅ 普通用户,准备调用 Get.toNamed\n' - '路由: ${Routes.KR_PURCHASE_MEMBERSHIP}\n' - '时间: ${DateTime.now()}\n' - '版本标识: Android15_Fix_v7_DialogFixed\n' - '-' * 60 + '\n', - mode: FileMode.append, - ); - } catch (e) { /* 忽略 */ } - }); - try { - print('🔔 [NavigationUtil] 📍 步骤1: 正在调用 Get.toNamed(${Routes.KR_PURCHASE_MEMBERSHIP})...'); - final result = Get.toNamed(Routes.KR_PURCHASE_MEMBERSHIP); - print('🔔 [NavigationUtil] 📍 步骤2: Get.toNamed 调用完成,返回值: $result'); - - Future(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/NAVIGATION_DEBUG.txt'); - await debugFile.writeAsString( - '✅ Get.toNamed 执行完成\n' - '路由: ${Routes.KR_PURCHASE_MEMBERSHIP}\n' - '返回值: $result\n' - '时间: ${DateTime.now()}\n' - '-' * 60 + '\n', - mode: FileMode.append, - ); - } catch (e) { - print('🔔 [NavigationUtil] ❌ 写入跳转完成日志失败: $e'); - } - }); + Get.toNamed(Routes.KR_PURCHASE_MEMBERSHIP); } catch (e) { KRLogUtil.kr_e('跳转购买页面失败: $e', tag: tag); - print('🔔 [NavigationUtil] ❌❌❌ 跳转异常: $e'); - - Future(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/NAVIGATION_DEBUG.txt'); - await debugFile.writeAsString( - '❌ Get.toNamed 执行失败\n' - '异常: $e\n' - '时间: ${DateTime.now()}\n' - '-' * 60 + '\n', - mode: FileMode.append, - ); - } catch (e) { - print('🔔 [NavigationUtil] ❌ 写入跳转失败日志失败: $e'); - } - }); // 如果跳转失败,显示错误提示 KRDialog.show( diff --git a/lib/app/widgets/dialogs/kr_dialog.dart b/lib/app/widgets/dialogs/kr_dialog.dart index ae94503..7d3d439 100755 --- a/lib/app/widgets/dialogs/kr_dialog.dart +++ b/lib/app/widgets/dialogs/kr_dialog.dart @@ -1,8 +1,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:kaer_with_panels/app/localization/app_translations.dart'; -import 'dart:io'; -import 'package:path_provider/path_provider.dart'; class KRDialog extends StatelessWidget { final String? title; @@ -36,31 +34,6 @@ class KRDialog extends StatelessWidget { Widget? icon, Widget? customMessageWidget, }) { - // 🔧 Android 15 诊断:记录对话框显示事件 - print('📢 [KRDialog] ========== KRDialog.show() 被调用 =========='); - print('📢 [KRDialog] 标题: $title'); - print('📢 [KRDialog] 消息: $message'); - print('📢 [KRDialog] 当前时间: ${DateTime.now()}'); - - Future(() async { - try { - final dir = await getApplicationDocumentsDirectory(); - final debugFile = File('${dir.path}/DIALOG_DEBUG.txt'); - await debugFile.writeAsString( - '=' * 60 + '\n' - '📢 KRDialog.show() 被调用!\n' - '时间: ${DateTime.now()}\n' - '标题: $title\n' - '消息: $message\n' - '版本标识: Android15_Fix_v7_DialogFixed\n' - '=' * 60 + '\n', - mode: FileMode.append, - ); - } catch (e) { - print('📢 [KRDialog] ❌ 写入对话框日志失败: $e'); - } - }); - return Get.dialog( KRDialog( title: title, @@ -91,8 +64,7 @@ class KRDialog extends StatelessWidget { ), child: TextButton( onPressed: () { - print('📢 [KRDialog] 确认按钮被点击'); - Get.back(); + Get.back(); onConfirm?.call(); }, style: TextButton.styleFrom( @@ -122,10 +94,6 @@ class KRDialog extends StatelessWidget { final theme = Theme.of(context); final isDark = theme.brightness == Brightness.dark; - print('📢 [KRDialog] 开始构建对话框 Widget'); - print('📢 [KRDialog] 标题: $title'); - print('📢 [KRDialog] 主题模式: ${isDark ? "暗色" : "亮色"}'); - // 🔧 Android 15 关键修复:完全移除 ScreenUtil,使用固定像素值 return Dialog( backgroundColor: theme.cardColor, @@ -191,8 +159,7 @@ class KRDialog extends StatelessWidget { ), child: TextButton( onPressed: () { - print('📢 [KRDialog] 取消按钮被点击'); - Get.back(); + Get.back(); onCancel?.call(); }, style: TextButton.styleFrom(