|
|
@ -8,16 +8,57 @@ import '../../controllers/translation_controller.dart'; |
|
|
/// 翻译模式选择对话框 |
|
|
/// 翻译模式选择对话框 |
|
|
class TranslationModeSelector { |
|
|
class TranslationModeSelector { |
|
|
/// 显示翻译模式选择器 |
|
|
/// 显示翻译模式选择器 |
|
|
static void show(bool isDarkMode) { |
|
|
static void show(bool isDarkMode, {Offset? anchor}) { |
|
|
final controller = Get.find<TranslationController>(); |
|
|
final controller = Get.find<TranslationController>(); |
|
|
|
|
|
|
|
|
Get.bottomSheet( |
|
|
// 计算缩放对齐点(-1..1)。如果未提供 anchor,则从底部中间展开 |
|
|
BackdropFilter( |
|
|
Alignment alignment = Alignment.bottomCenter; |
|
|
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), |
|
|
if (anchor != null) { |
|
|
child: _buildTranslationModeSelector(controller), |
|
|
final Size screenSize = MediaQuery.of(Get.context!).size; |
|
|
), |
|
|
final double ax = (anchor.dx / screenSize.width) * 2 - 1; |
|
|
isScrollControlled: true, |
|
|
final double ay = (anchor.dy / screenSize.height) * 2 - 1; |
|
|
backgroundColor: Colors.transparent, |
|
|
alignment = Alignment(ax, ay); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Get.generalDialog( |
|
|
|
|
|
barrierLabel: 'translation_mode_selector', |
|
|
|
|
|
barrierDismissible: true, |
|
|
|
|
|
barrierColor: Colors.black.withOpacity(0.35), |
|
|
|
|
|
transitionDuration: const Duration(milliseconds: 250), |
|
|
|
|
|
pageBuilder: (context, animation, secondaryAnimation) { |
|
|
|
|
|
return const SizedBox.shrink(); |
|
|
|
|
|
}, |
|
|
|
|
|
transitionBuilder: (context, animation, secondaryAnimation, child) { |
|
|
|
|
|
final curved = CurvedAnimation( |
|
|
|
|
|
parent: animation, |
|
|
|
|
|
curve: Curves.easeOutCubic, |
|
|
|
|
|
reverseCurve: Curves.easeInCubic); |
|
|
|
|
|
return Stack( |
|
|
|
|
|
children: [ |
|
|
|
|
|
// 模糊背景 |
|
|
|
|
|
Positioned.fill( |
|
|
|
|
|
child: BackdropFilter( |
|
|
|
|
|
filter: ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0), |
|
|
|
|
|
child: Container(color: Colors.transparent), |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
// 将缩放应用在一个全屏容器上,以便 alignment 以屏幕为参考 |
|
|
|
|
|
ScaleTransition( |
|
|
|
|
|
alignment: alignment, |
|
|
|
|
|
scale: Tween<double>(begin: 0.0, end: 1.0).animate(curved), |
|
|
|
|
|
child: FadeTransition( |
|
|
|
|
|
opacity: curved, |
|
|
|
|
|
child: SizedBox.expand( |
|
|
|
|
|
child: Align( |
|
|
|
|
|
alignment: Alignment.bottomCenter, |
|
|
|
|
|
child: _buildTranslationModeSelector(controller), |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
), |
|
|
|
|
|
], |
|
|
|
|
|
); |
|
|
|
|
|
}, |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|