zefyr

slide_page_transition_builder.dart 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. part of ct_assets_picker;
  2. ///
  3. /// [Author] Alex (https://github.com/Alex525)
  4. /// [Date] 2020/4/13 18:04
  5. ///
  6. /// Built a slide page transition for the picker.
  7. /// 为选择器构造一个上下进出的页面过渡动画
  8. class SlidePageTransitionBuilder<T> extends PageRoute<T> {
  9. SlidePageTransitionBuilder({
  10. @required this.builder,
  11. this.transitionCurve = Curves.easeIn,
  12. this.transitionDuration = const Duration(milliseconds: 500),
  13. });
  14. final Widget builder;
  15. final Curve transitionCurve;
  16. @override
  17. final Duration transitionDuration;
  18. @override
  19. final bool opaque = true;
  20. @override
  21. final bool barrierDismissible = false;
  22. @override
  23. final bool maintainState = true;
  24. @override
  25. Color get barrierColor => null;
  26. @override
  27. String get barrierLabel => null;
  28. @override
  29. Widget buildPage(
  30. BuildContext context,
  31. Animation<double> animation,
  32. Animation<double> secondaryAnimation,
  33. ) {
  34. return builder;
  35. }
  36. @override
  37. Widget buildTransitions(
  38. BuildContext context,
  39. Animation<double> animation,
  40. Animation<double> secondaryAnimation,
  41. Widget child,
  42. ) {
  43. return SlideTransition(
  44. position: Tween<Offset>(
  45. begin: const Offset(0, 1),
  46. end: Offset.zero,
  47. ).animate(CurvedAnimation(
  48. curve: transitionCurve,
  49. parent: animation,
  50. )),
  51. child: child,
  52. );
  53. }
  54. }