|
|
@ -55,19 +55,7 @@ class DraggableFloatingButton extends StatelessWidget { |
|
|
), |
|
|
), |
|
|
), |
|
|
), |
|
|
onDragEnd: (details) { |
|
|
onDragEnd: (details) { |
|
|
// 计算新位置(相对于屏幕右下角) |
|
|
_handleDragEnd(context, details); |
|
|
final screenSize = MediaQuery.of(Get.context!).size; |
|
|
|
|
|
final newRight = screenSize.width - details.offset.dx - 56.w; |
|
|
|
|
|
final newBottom = screenSize.height - details.offset.dy - 56.w; |
|
|
|
|
|
|
|
|
|
|
|
// 边界检查,确保按钮不会超出屏幕 |
|
|
|
|
|
final clampedRight = newRight.clamp(0.0, screenSize.width - 56.w); |
|
|
|
|
|
final clampedBottom = |
|
|
|
|
|
newBottom.clamp(0.0, screenSize.height - 56.w); |
|
|
|
|
|
|
|
|
|
|
|
// 保存新位置 |
|
|
|
|
|
controller.saveFloatingButtonPosition( |
|
|
|
|
|
Offset(clampedRight, clampedBottom)); |
|
|
|
|
|
}, |
|
|
}, |
|
|
child: GestureDetector( |
|
|
child: GestureDetector( |
|
|
onTap: () => _showTranslationModeSelector(isDarkMode), |
|
|
onTap: () => _showTranslationModeSelector(isDarkMode), |
|
|
@ -96,6 +84,28 @@ class DraggableFloatingButton extends StatelessWidget { |
|
|
)); |
|
|
)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// 处理拖拽结束事件 |
|
|
|
|
|
void _handleDragEnd(BuildContext context, DraggableDetails details) { |
|
|
|
|
|
final screenSize = MediaQuery.of(context).size; |
|
|
|
|
|
final appBarHeight = Scaffold.of(context).appBarMaxHeight ?? kToolbarHeight; |
|
|
|
|
|
final statusBarHeight = MediaQuery.of(context).padding.top; |
|
|
|
|
|
final safeAreaTop = statusBarHeight + appBarHeight; |
|
|
|
|
|
|
|
|
|
|
|
// 计算新位置(相对于屏幕右下角) |
|
|
|
|
|
final newRight = screenSize.width - details.offset.dx - 56.w; |
|
|
|
|
|
final newBottom = screenSize.height - details.offset.dy - 56.w; |
|
|
|
|
|
|
|
|
|
|
|
// 边界检查,确保按钮不会超出屏幕或被AppBar遮盖 |
|
|
|
|
|
final clampedRight = newRight.clamp(0.0, screenSize.width - 56.w); |
|
|
|
|
|
final clampedBottom = newBottom.clamp( |
|
|
|
|
|
0.0, // 底部边界 |
|
|
|
|
|
screenSize.height - safeAreaTop - 56.w, // 顶部边界(避免被AppBar遮盖) |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// 保存新位置 |
|
|
|
|
|
controller.saveFloatingButtonPosition(Offset(clampedRight, clampedBottom)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/// 显示翻译模式选择器 |
|
|
/// 显示翻译模式选择器 |
|
|
void _showTranslationModeSelector(bool isDarkMode) { |
|
|
void _showTranslationModeSelector(bool isDarkMode) { |
|
|
TranslationModeSelector.show(isDarkMode); |
|
|
TranslationModeSelector.show(isDarkMode); |
|
|
|