1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import 'dart:collection';
- import 'package:animations/animations.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- ///页面过度动效
- class FTransitions {
- FTransitions._();
- static final _cache = HashMap<String, CustomTransition>();
- static CustomTransition get fadeThrough => _findInCache(() => _FadeThrough());
- static CustomTransition get sharedAxisHorizontal => _findInCache(
- () => _SharedAxis(SharedAxisTransitionType.horizontal),
- tag: "x",
- );
- static CustomTransition get sharedAxisVertical => _findInCache(
- () => _SharedAxis(SharedAxisTransitionType.vertical),
- tag: "y",
- );
- static CustomTransition get sharedAxisScaled => _findInCache(
- () => _SharedAxis(SharedAxisTransitionType.scaled),
- tag: "z",
- );
- static CustomTransition _findInCache<T extends CustomTransition>(
- T Function() builder, {
- String? tag,
- }) {
- final key = tag != null ? '${T.toString()}_$tag' : T.toString();
- if (!_cache.containsKey(key)) {
- _cache[key] = builder();
- }
- return _cache[key]!;
- }
- }
- ///公用过度动效轴
- class _SharedAxis extends CustomTransition {
- _SharedAxis(this.transitionType);
- final SharedAxisTransitionType transitionType;
- @override
- Widget buildTransition(
- BuildContext context,
- Curve? curve,
- Alignment? alignment,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- Widget child,
- ) {
- return SharedAxisTransition(
- animation: animation,
- secondaryAnimation: secondaryAnimation,
- transitionType: transitionType,
- child: child,
- );
- }
- }
- ///闪现过度动效
- class _FadeThrough extends CustomTransition {
- @override
- Widget buildTransition(
- BuildContext context,
- Curve? curve,
- Alignment? alignment,
- Animation<double> animation,
- Animation<double> secondaryAnimation,
- Widget child,
- ) {
- return FadeThroughTransition(
- animation: animation,
- secondaryAnimation: secondaryAnimation,
- child: child,
- );
- }
- }
|