feat: 更新代码仓库全部修改
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled
Build Windows / build (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,240 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
enum SlideDirection { leftToRight, rightToLeft }
|
||||
|
||||
/// 智能转场类,根据路由上下文决定转场方向
|
||||
class ContextAwareSlideTransition extends CustomTransition {
|
||||
final String targetRoute;
|
||||
final Duration duration;
|
||||
|
||||
ContextAwareSlideTransition({
|
||||
required this.targetRoute,
|
||||
this.duration = const Duration(milliseconds: 350),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget buildTransition(
|
||||
BuildContext context,
|
||||
Curve? curve,
|
||||
Alignment? alignment,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child) {
|
||||
|
||||
// 获取当前路由信息
|
||||
final currentRoute = Get.currentRoute;
|
||||
final previousRoute = Get.previousRoute;
|
||||
|
||||
// 决定转场方向
|
||||
SlideDirection direction = _determineDirection(currentRoute, previousRoute);
|
||||
|
||||
// 确保移动距离一致:都是1.0个屏幕宽度
|
||||
const double slideDistance = 1.0;
|
||||
|
||||
// 新页面入场方向
|
||||
final newPageBeginOffset = direction == SlideDirection.rightToLeft
|
||||
? Offset(slideDistance, 0)
|
||||
: Offset(-slideDistance, 0);
|
||||
|
||||
// 旧页面滑出方向(与新页面相反,距离相同)
|
||||
final oldPageEndOffset = direction == SlideDirection.rightToLeft
|
||||
? Offset(-slideDistance, 0)
|
||||
: Offset(slideDistance, 0);
|
||||
|
||||
// 使用相同的动画曲线确保同步
|
||||
final animationCurve = curve ?? Curves.elasticOut;
|
||||
|
||||
// 新页面滑入动画:从屏幕外滑入到中心
|
||||
final newPageAnimation = Tween<Offset>(
|
||||
begin: newPageBeginOffset,
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: animationCurve,
|
||||
));
|
||||
|
||||
// 旧页面滑出动画:从中心滑出到屏幕外
|
||||
final oldPageAnimation = Tween<Offset>(
|
||||
begin: Offset.zero,
|
||||
end: oldPageEndOffset,
|
||||
).animate(CurvedAnimation(
|
||||
parent: secondaryAnimation,
|
||||
curve: animationCurve,
|
||||
));
|
||||
|
||||
// 使用 AnimatedBuilder 来监听 secondaryAnimation 的变化
|
||||
return AnimatedBuilder(
|
||||
animation: secondaryAnimation,
|
||||
builder: (context, _) {
|
||||
// 如果 secondaryAnimation 正在运行,说明这是旧页面
|
||||
if (secondaryAnimation.status == AnimationStatus.forward ||
|
||||
secondaryAnimation.status == AnimationStatus.reverse) {
|
||||
return SlideTransition(
|
||||
position: oldPageAnimation,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
// 否则这是新页面
|
||||
return SlideTransition(
|
||||
position: newPageAnimation,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 根据路由上下文决定转场方向
|
||||
SlideDirection _determineDirection(String currentRoute, String previousRoute) {
|
||||
// 如果目标路由是 HI_MENU
|
||||
if (targetRoute == '/hi_menu') {
|
||||
// 从 home 页面来的,使用左到右(menu 从左侧进入)
|
||||
if (previousRoute == '/kr_home' || previousRoute.contains('kr_home')) {
|
||||
return SlideDirection.leftToRight;
|
||||
}
|
||||
// 去其他页面,使用右到左
|
||||
else {
|
||||
return SlideDirection.rightToLeft;
|
||||
}
|
||||
}
|
||||
|
||||
// 默认使用右到左
|
||||
return SlideDirection.rightToLeft;
|
||||
}
|
||||
}
|
||||
|
||||
class SlideTransparentTransition extends CustomTransition {
|
||||
final SlideDirection direction;
|
||||
final Duration duration;
|
||||
|
||||
SlideTransparentTransition({
|
||||
this.direction = SlideDirection.rightToLeft,
|
||||
this.duration = const Duration(milliseconds: 4000),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget buildTransition(
|
||||
BuildContext context,
|
||||
Curve? curve,
|
||||
Alignment? alignment,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child) {
|
||||
|
||||
// 确保移动距离一致:都是1.0个屏幕宽度
|
||||
const double slideDistance = 1.0;
|
||||
|
||||
// 新页面入场方向
|
||||
final newPageBeginOffset = direction == SlideDirection.rightToLeft
|
||||
? Offset(slideDistance, 0)
|
||||
: Offset(-slideDistance, 0);
|
||||
|
||||
// 旧页面滑出方向(与新页面相反,距离相同)
|
||||
final oldPageEndOffset = direction == SlideDirection.rightToLeft
|
||||
? Offset(-slideDistance, 0)
|
||||
: Offset(slideDistance, 0);
|
||||
|
||||
// 使用相同的动画曲线确保同步
|
||||
final animationCurve = curve ?? Curves.elasticOut;
|
||||
|
||||
// 新页面滑入动画:从屏幕外滑入到中心
|
||||
final newPageAnimation = Tween<Offset>(
|
||||
begin: newPageBeginOffset,
|
||||
end: Offset.zero,
|
||||
).animate(CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: animationCurve,
|
||||
));
|
||||
|
||||
// 旧页面滑出动画:从中心滑出到屏幕外
|
||||
final oldPageAnimation = Tween<Offset>(
|
||||
begin: Offset.zero,
|
||||
end: oldPageEndOffset,
|
||||
).animate(CurvedAnimation(
|
||||
parent: secondaryAnimation,
|
||||
curve: animationCurve,
|
||||
));
|
||||
|
||||
// 使用 AnimatedBuilder 来监听 secondaryAnimation 的变化
|
||||
return AnimatedBuilder(
|
||||
animation: secondaryAnimation,
|
||||
builder: (context, _) {
|
||||
// 如果 secondaryAnimation 正在运行,说明这是旧页面
|
||||
if (secondaryAnimation.status == AnimationStatus.forward ||
|
||||
secondaryAnimation.status == AnimationStatus.reverse) {
|
||||
return SlideTransition(
|
||||
position: oldPageAnimation,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
// 否则这是新页面
|
||||
return SlideTransition(
|
||||
position: newPageAnimation,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class SlideOutOnlyTransition extends CustomTransition {
|
||||
final SlideDirection direction;
|
||||
final Duration duration;
|
||||
|
||||
SlideOutOnlyTransition({
|
||||
this.direction = SlideDirection.rightToLeft,
|
||||
this.duration = const Duration(milliseconds: 350),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget buildTransition(
|
||||
BuildContext context,
|
||||
Curve? curve,
|
||||
Alignment? alignment,
|
||||
Animation<double> animation,
|
||||
Animation<double> secondaryAnimation,
|
||||
Widget child) {
|
||||
|
||||
const double slideDistance = 1.0;
|
||||
|
||||
// 旧页面出场动画
|
||||
final oldPageEndOffset = direction == SlideDirection.rightToLeft
|
||||
? Offset(-slideDistance, 0)
|
||||
: Offset(slideDistance, 0);
|
||||
|
||||
final oldPageAnimation = Tween<Offset>(
|
||||
begin: Offset.zero,
|
||||
end: oldPageEndOffset,
|
||||
).animate(CurvedAnimation(
|
||||
parent: secondaryAnimation,
|
||||
curve: curve ?? Curves.easeOut,
|
||||
));
|
||||
|
||||
// 新页面入场无动画
|
||||
final newPageAnimation = Tween<Offset>(
|
||||
begin: Offset.zero,
|
||||
end: Offset.zero,
|
||||
).animate(animation);
|
||||
|
||||
return AnimatedBuilder(
|
||||
animation: secondaryAnimation,
|
||||
builder: (context, _) {
|
||||
// secondaryAnimation 正在执行,表示旧页面在出场
|
||||
if (secondaryAnimation.status == AnimationStatus.forward ||
|
||||
secondaryAnimation.status == AnimationStatus.reverse) {
|
||||
return SlideTransition(
|
||||
position: oldPageAnimation,
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
// 否则新页面直接显示,无动画
|
||||
return SlideTransition(
|
||||
position: newPageAnimation,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'slide_transparent_transition.dart';
|
||||
|
||||
/// 全局页面过渡动画配置类
|
||||
class TransitionConfig {
|
||||
static Duration _defaultDuration = const Duration(milliseconds: 350);
|
||||
static const SlideDirection _defaultDirection = SlideDirection.rightToLeft;
|
||||
static const Curve _defaultCurve = Curves.easeOutCubic;
|
||||
|
||||
/// 默认动画持续时间
|
||||
static Duration get defaultDuration => _defaultDuration;
|
||||
|
||||
/// 默认滑动方向
|
||||
static SlideDirection get defaultDirection => _defaultDirection;
|
||||
|
||||
/// 默认动画曲线
|
||||
static Curve get defaultCurve => _defaultCurve;
|
||||
|
||||
/// 创建默认的滑动过渡动画
|
||||
static SlideTransparentTransition createDefaultTransition() {
|
||||
return SlideTransparentTransition(
|
||||
direction: _defaultDirection,
|
||||
duration: _defaultDuration,
|
||||
);
|
||||
}
|
||||
|
||||
/// 创建自定义滑动过渡动画
|
||||
static SlideTransparentTransition createCustomTransition({
|
||||
SlideDirection? direction,
|
||||
Duration? duration,
|
||||
}) {
|
||||
return SlideTransparentTransition(
|
||||
direction: direction ?? _defaultDirection,
|
||||
duration: duration ?? _defaultDuration,
|
||||
);
|
||||
}
|
||||
|
||||
/// 创建从左到右的过渡动画(通常用于返回操作)
|
||||
static SlideTransparentTransition createLeftToRightTransition({
|
||||
Duration? duration,
|
||||
}) {
|
||||
return SlideTransparentTransition(
|
||||
direction: SlideDirection.leftToRight,
|
||||
duration: duration ?? _defaultDuration,
|
||||
);
|
||||
}
|
||||
|
||||
/// 创建从右到左的过渡动画(通常用于前进操作)
|
||||
static SlideTransparentTransition createRightToLeftTransition({
|
||||
Duration? duration,
|
||||
}) {
|
||||
return SlideTransparentTransition(
|
||||
direction: SlideDirection.rightToLeft,
|
||||
duration: duration ?? _defaultDuration,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 全局路由助手类
|
||||
class RouteHelper {
|
||||
/// 使用自定义过渡动画跳转到指定页面
|
||||
static Future<T?>? toWithCustomTransition<T>(
|
||||
Widget page, {
|
||||
SlideDirection? direction,
|
||||
Duration? duration,
|
||||
bool? opaque,
|
||||
Curve? curve,
|
||||
String? routeName,
|
||||
bool fullscreenDialog = false,
|
||||
dynamic arguments,
|
||||
Bindings? binding,
|
||||
bool preventDuplicates = true,
|
||||
bool? popGesture,
|
||||
}) {
|
||||
// 使用 Get.to 并依赖全局配置的 customTransition
|
||||
return Get.to<T>(
|
||||
page,
|
||||
duration: duration ?? TransitionConfig.defaultDuration,
|
||||
opaque: opaque,
|
||||
curve: curve ?? TransitionConfig.defaultCurve,
|
||||
routeName: routeName,
|
||||
fullscreenDialog: fullscreenDialog,
|
||||
arguments: arguments,
|
||||
binding: binding,
|
||||
preventDuplicates: preventDuplicates,
|
||||
popGesture: popGesture,
|
||||
);
|
||||
}
|
||||
|
||||
/// 使用自定义过渡动画跳转到命名路由
|
||||
static Future<T?>? toNamedWithCustomTransition<T>(
|
||||
String page, {
|
||||
dynamic arguments,
|
||||
bool preventDuplicates = true,
|
||||
Map<String, String>? parameters,
|
||||
}) {
|
||||
return Get.toNamed<T>(
|
||||
page,
|
||||
arguments: arguments,
|
||||
preventDuplicates: preventDuplicates,
|
||||
parameters: parameters,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user