transition.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import 'dart:collection';
  2. import 'package:animations/animations.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. ///页面过度动效
  6. class FTransitions {
  7. FTransitions._();
  8. static final _cache = HashMap<String, CustomTransition>();
  9. static CustomTransition get fadeThrough => _findInCache(() => _FadeThrough());
  10. static CustomTransition get sharedAxisHorizontal => _findInCache(
  11. () => _SharedAxis(SharedAxisTransitionType.horizontal),
  12. tag: "x",
  13. );
  14. static CustomTransition get sharedAxisVertical => _findInCache(
  15. () => _SharedAxis(SharedAxisTransitionType.vertical),
  16. tag: "y",
  17. );
  18. static CustomTransition get sharedAxisScaled => _findInCache(
  19. () => _SharedAxis(SharedAxisTransitionType.scaled),
  20. tag: "z",
  21. );
  22. static CustomTransition _findInCache<T extends CustomTransition>(
  23. T Function() builder, {
  24. String? tag,
  25. }) {
  26. final key = tag != null ? '${T.toString()}_$tag' : T.toString();
  27. if (!_cache.containsKey(key)) {
  28. _cache[key] = builder();
  29. }
  30. return _cache[key]!;
  31. }
  32. }
  33. ///公用过度动效轴
  34. class _SharedAxis extends CustomTransition {
  35. _SharedAxis(this.transitionType);
  36. final SharedAxisTransitionType transitionType;
  37. @override
  38. Widget buildTransition(
  39. BuildContext context,
  40. Curve? curve,
  41. Alignment? alignment,
  42. Animation<double> animation,
  43. Animation<double> secondaryAnimation,
  44. Widget child,
  45. ) {
  46. return SharedAxisTransition(
  47. animation: animation,
  48. secondaryAnimation: secondaryAnimation,
  49. transitionType: transitionType,
  50. child: child,
  51. );
  52. }
  53. }
  54. ///闪现过度动效
  55. class _FadeThrough extends CustomTransition {
  56. @override
  57. Widget buildTransition(
  58. BuildContext context,
  59. Curve? curve,
  60. Alignment? alignment,
  61. Animation<double> animation,
  62. Animation<double> secondaryAnimation,
  63. Widget child,
  64. ) {
  65. return FadeThroughTransition(
  66. animation: animation,
  67. secondaryAnimation: secondaryAnimation,
  68. child: child,
  69. );
  70. }
  71. }