diff --git a/lib/modules/translation/controllers/translation_controller.dart b/lib/modules/translation/controllers/translation_controller.dart index d19416b96..fc02d93a8 100644 --- a/lib/modules/translation/controllers/translation_controller.dart +++ b/lib/modules/translation/controllers/translation_controller.dart @@ -410,14 +410,12 @@ class TranslationController extends GetxController with WidgetsBindingObserver { WidgetsBinding.instance.addObserver(this); // 延迟显示模式选择器,确保页面已经完全加载 - WidgetsBinding.instance.addPostFrameCallback((_) async { - // 确保上下文有效 - if (Get.context == null || !Get.context!.mounted) return; + // WidgetsBinding.instance.addPostFrameCallback((_) async { + // // 确保上下文有效 + // if (Get.context == null || !Get.context!.mounted) return; - // Future.delayed(const Duration(milliseconds: 200), () { - _showModeSelector(); - // }); - }); + // _showModeSelector(); + // }); } /// 预先检查权限 diff --git a/lib/modules/translation/views/dialogs/translation_mode_selector.dart b/lib/modules/translation/views/dialogs/translation_mode_selector.dart index 50bde22e0..761091023 100644 --- a/lib/modules/translation/views/dialogs/translation_mode_selector.dart +++ b/lib/modules/translation/views/dialogs/translation_mode_selector.dart @@ -10,22 +10,29 @@ class TranslationModeSelector { /// 显示翻译模式选择器 static void show(bool isDarkMode, {Offset? anchor}) { final controller = Get.find(); - - // 总是从悬浮按钮位置展开,不依赖传入的anchor参数 final Size screenSize = MediaQuery.of(Get.context!).size; - final Offset floatingButtonPos = controller.floatingButtonPosition.value; - // 计算悬浮按钮的中心点位置(从右下角偏移转换为屏幕坐标) - final double buttonSize = 56.0.w; // 悬浮按钮的大小 - final double buttonCenterX = - screenSize.width - floatingButtonPos.dx - buttonSize / 2; - final double buttonCenterY = - screenSize.height - floatingButtonPos.dy - buttonSize / 2; + Alignment alignment; + + if (anchor != null) { + // 使用传入的锚点计算对齐点 + final double ax = (anchor.dx / screenSize.width) * 2 - 1; + final double ay = (anchor.dy / screenSize.height) * 2 - 1; + alignment = Alignment(ax, ay); + } else { + final Offset floatingButtonPos = controller.floatingButtonPosition.value; + // 计算悬浮按钮的中心点位置(从右下角偏移转换为屏幕坐标) + final double buttonSize = 56.0.w; // 悬浮按钮的大小 + final double buttonCenterX = + screenSize.width - floatingButtonPos.dx - buttonSize / 2; + final double buttonCenterY = + screenSize.height - floatingButtonPos.dy - buttonSize / 2; - // 计算缩放对齐点(-1..1) - final double ax = (buttonCenterX / screenSize.width) * 2 - 1; - final double ay = (buttonCenterY / screenSize.height) * 2 - 1; - final Alignment alignment = Alignment(ax, ay); + // 计算缩放对齐点(-1..1) + final double ax = (buttonCenterX / screenSize.width) * 2 - 1; + final double ay = (buttonCenterY / screenSize.height) * 2 - 1; + alignment = Alignment(ax, ay); + } Get.generalDialog( barrierLabel: 'translation_mode_selector', @@ -93,7 +100,7 @@ class TranslationModeSelector { Get.back(); await controller.stopAll(); await controller.changeTranslationMode('simultaneous'); - //await controller.startRecognition(); + await controller.startRecognition(); }, ), _buildModeItem( @@ -106,7 +113,7 @@ class TranslationModeSelector { Get.back(); await controller.stopAll(); await controller.changeTranslationMode('faceToFace'); - //await controller.startRecognition(); + await controller.startRecognition(); }, ), _buildModeItem( @@ -120,7 +127,7 @@ class TranslationModeSelector { Get.back(); await controller.stopAll(); await controller.changeTranslationMode('audioVideo'); - //await controller.startRecognition(); + await controller.startRecognition(); } : null, ), @@ -135,23 +142,23 @@ class TranslationModeSelector { Get.back(); await controller.stopAll(); await controller.changeTranslationMode('call'); - //await controller.startRecognition(); + await controller.startRecognition(); } : null, ), - SizedBox(height: 64.w), - // GestureDetector( - // onTap: () => Get.back(), - // child: Container( - // width: 42, - // height: 42, - // decoration: BoxDecoration( - // color: Colors.black.withValues(alpha: 0.8), - // borderRadius: BorderRadius.circular(50), - // ), - // child: const Icon(Icons.close, color: Colors.white), - // ), - // ), + SizedBox(height: 24.w), + GestureDetector( + onTap: () => Get.back(), + child: Container( + width: 42, + height: 42, + decoration: BoxDecoration( + color: Colors.black.withValues(alpha: 0.8), + borderRadius: BorderRadius.circular(50), + ), + child: const Icon(Icons.close, color: Colors.white), + ), + ), if (Platform.isAndroid) SizedBox(height: 20.h), ], ), diff --git a/lib/modules/translation/views/translation_view.dart b/lib/modules/translation/views/translation_view.dart index c83578930..1a1fd9aad 100644 --- a/lib/modules/translation/views/translation_view.dart +++ b/lib/modules/translation/views/translation_view.dart @@ -45,10 +45,10 @@ class TranslationView extends GetView { children: [ _buildBody(isDarkMode), // 可拖拽的悬浮按钮 - DraggableFloatingButton( - isDarkMode: isDarkMode, - controller: controller, - ), + // DraggableFloatingButton( + // isDarkMode: isDarkMode, + // controller: controller, + // ), ], ), ); @@ -633,7 +633,26 @@ class TranslationView extends GetView { if (isRecognizing) { controller.stopAll(); } else { - controller.startRecognition(); + // 获取底部按钮的位置 + if (controlBarKey.currentContext != null) { + final RenderBox renderBox = + controlBarKey.currentContext!.findRenderObject() + as RenderBox; + final buttonPosition = + renderBox.localToGlobal(Offset.zero); + final buttonSize = renderBox.size; + + // 计算按钮中心点 + final Offset anchor = buttonPosition + + Offset(buttonSize.width / 2, + buttonSize.height / 2); + TranslationModeSelector.show(isDarkMode, + anchor: anchor); + + //controller.startRecognition(); + } else { + TranslationModeSelector.show(isDarkMode); + } } }, child: Container(