Some checks failed
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
106 lines
3.0 KiB
Dart
106 lines
3.0 KiB
Dart
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,
|
|
);
|
|
}
|
|
}
|