|
|
@ -10,22 +10,29 @@ class TranslationModeSelector { |
|
|
/// 显示翻译模式选择器 |
|
|
/// 显示翻译模式选择器 |
|
|
static void show(bool isDarkMode, {Offset? anchor}) { |
|
|
static void show(bool isDarkMode, {Offset? anchor}) { |
|
|
final controller = Get.find<TranslationController>(); |
|
|
final controller = Get.find<TranslationController>(); |
|
|
|
|
|
|
|
|
// 总是从悬浮按钮位置展开,不依赖传入的anchor参数 |
|
|
|
|
|
final Size screenSize = MediaQuery.of(Get.context!).size; |
|
|
final Size screenSize = MediaQuery.of(Get.context!).size; |
|
|
final Offset floatingButtonPos = controller.floatingButtonPosition.value; |
|
|
|
|
|
|
|
|
|
|
|
// 计算悬浮按钮的中心点位置(从右下角偏移转换为屏幕坐标) |
|
|
Alignment alignment; |
|
|
final double buttonSize = 56.0.w; // 悬浮按钮的大小 |
|
|
|
|
|
final double buttonCenterX = |
|
|
if (anchor != null) { |
|
|
screenSize.width - floatingButtonPos.dx - buttonSize / 2; |
|
|
// 使用传入的锚点计算对齐点 |
|
|
final double buttonCenterY = |
|
|
final double ax = (anchor.dx / screenSize.width) * 2 - 1; |
|
|
screenSize.height - floatingButtonPos.dy - buttonSize / 2; |
|
|
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) |
|
|
// 计算缩放对齐点(-1..1) |
|
|
final double ax = (buttonCenterX / screenSize.width) * 2 - 1; |
|
|
final double ax = (buttonCenterX / screenSize.width) * 2 - 1; |
|
|
final double ay = (buttonCenterY / screenSize.height) * 2 - 1; |
|
|
final double ay = (buttonCenterY / screenSize.height) * 2 - 1; |
|
|
final Alignment alignment = Alignment(ax, ay); |
|
|
alignment = Alignment(ax, ay); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Get.generalDialog( |
|
|
Get.generalDialog( |
|
|
barrierLabel: 'translation_mode_selector', |
|
|
barrierLabel: 'translation_mode_selector', |
|
|
@ -93,7 +100,7 @@ class TranslationModeSelector { |
|
|
Get.back(); |
|
|
Get.back(); |
|
|
await controller.stopAll(); |
|
|
await controller.stopAll(); |
|
|
await controller.changeTranslationMode('simultaneous'); |
|
|
await controller.changeTranslationMode('simultaneous'); |
|
|
//await controller.startRecognition(); |
|
|
await controller.startRecognition(); |
|
|
}, |
|
|
}, |
|
|
), |
|
|
), |
|
|
_buildModeItem( |
|
|
_buildModeItem( |
|
|
@ -106,7 +113,7 @@ class TranslationModeSelector { |
|
|
Get.back(); |
|
|
Get.back(); |
|
|
await controller.stopAll(); |
|
|
await controller.stopAll(); |
|
|
await controller.changeTranslationMode('faceToFace'); |
|
|
await controller.changeTranslationMode('faceToFace'); |
|
|
//await controller.startRecognition(); |
|
|
await controller.startRecognition(); |
|
|
}, |
|
|
}, |
|
|
), |
|
|
), |
|
|
_buildModeItem( |
|
|
_buildModeItem( |
|
|
@ -120,7 +127,7 @@ class TranslationModeSelector { |
|
|
Get.back(); |
|
|
Get.back(); |
|
|
await controller.stopAll(); |
|
|
await controller.stopAll(); |
|
|
await controller.changeTranslationMode('audioVideo'); |
|
|
await controller.changeTranslationMode('audioVideo'); |
|
|
//await controller.startRecognition(); |
|
|
await controller.startRecognition(); |
|
|
} |
|
|
} |
|
|
: null, |
|
|
: null, |
|
|
), |
|
|
), |
|
|
@ -135,23 +142,23 @@ class TranslationModeSelector { |
|
|
Get.back(); |
|
|
Get.back(); |
|
|
await controller.stopAll(); |
|
|
await controller.stopAll(); |
|
|
await controller.changeTranslationMode('call'); |
|
|
await controller.changeTranslationMode('call'); |
|
|
//await controller.startRecognition(); |
|
|
await controller.startRecognition(); |
|
|
} |
|
|
} |
|
|
: null, |
|
|
: null, |
|
|
), |
|
|
), |
|
|
SizedBox(height: 64.w), |
|
|
SizedBox(height: 24.w), |
|
|
// GestureDetector( |
|
|
GestureDetector( |
|
|
// onTap: () => Get.back(), |
|
|
onTap: () => Get.back(), |
|
|
// child: Container( |
|
|
child: Container( |
|
|
// width: 42, |
|
|
width: 42, |
|
|
// height: 42, |
|
|
height: 42, |
|
|
// decoration: BoxDecoration( |
|
|
decoration: BoxDecoration( |
|
|
// color: Colors.black.withValues(alpha: 0.8), |
|
|
color: Colors.black.withValues(alpha: 0.8), |
|
|
// borderRadius: BorderRadius.circular(50), |
|
|
borderRadius: BorderRadius.circular(50), |
|
|
// ), |
|
|
), |
|
|
// child: const Icon(Icons.close, color: Colors.white), |
|
|
child: const Icon(Icons.close, color: Colors.white), |
|
|
// ), |
|
|
), |
|
|
// ), |
|
|
), |
|
|
if (Platform.isAndroid) SizedBox(height: 20.h), |
|
|
if (Platform.isAndroid) SizedBox(height: 20.h), |
|
|
], |
|
|
], |
|
|
), |
|
|
), |
|
|
|