animation.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import 'package:flutter/material.dart';
  2. class FadeRoute extends PageRouteBuilder {
  3. final Widget page;
  4. FadeRoute(this.page)
  5. : super(
  6. pageBuilder: (
  7. context,
  8. animation,
  9. secondaryAnimation,
  10. ) {
  11. return page;
  12. },
  13. transitionsBuilder: (
  14. context,
  15. animation,
  16. secondaryAnimation,
  17. child,
  18. ) {
  19. return FadeTransition(
  20. opacity: animation,
  21. child: child,
  22. );
  23. },
  24. );
  25. }
  26. class EnterExitRoute extends PageRouteBuilder {
  27. final Widget enterPage;
  28. final Widget exitPage;
  29. EnterExitRoute(this.enterPage, this.exitPage, bool rightDir)
  30. : super(
  31. pageBuilder: (
  32. context,
  33. animation,
  34. secondaryAnimation,
  35. ) {
  36. return exitPage;
  37. },
  38. transitionsBuilder: (
  39. context,
  40. animation,
  41. secondaryAnimation,
  42. child,
  43. ) =>
  44. Stack(
  45. children: [
  46. SlideTransition(
  47. position: rightDir ? Tween<Offset>(
  48. begin: Offset(0.0, 0.0),
  49. end: Offset(-1.0, 0.0),
  50. ).animate(
  51. CurvedAnimation(parent: animation, curve: Curves.easeIn),
  52. ) : Tween<Offset>(
  53. begin: Offset(0.0, 0.0),
  54. end: Offset(1.0, 0.0),
  55. ).animate(
  56. CurvedAnimation(parent: animation, curve: Curves.easeIn),
  57. ),
  58. child: enterPage,
  59. ),
  60. SlideTransition(
  61. position: rightDir ? Tween<Offset>(
  62. begin: Offset(1.0, 0.0),
  63. end: Offset.zero,
  64. ).animate(
  65. CurvedAnimation(parent: animation, curve: Curves.easeInOut),
  66. ) : Tween<Offset>(
  67. begin: Offset(-1.0, 0.0),
  68. end: Offset.zero,
  69. ).animate(
  70. CurvedAnimation(parent: animation, curve: Curves.easeInOut),
  71. ),
  72. child: exitPage,
  73. )
  74. ],
  75. ),
  76. );
  77. }
  78. class DownUpRoute extends PageRouteBuilder {
  79. final Widget enterPage;
  80. final Widget exitPage;
  81. DownUpRoute(this.enterPage, this.exitPage, bool rightDir)
  82. : super(
  83. pageBuilder: (
  84. context,
  85. animation,
  86. secondaryAnimation,
  87. ) {
  88. return exitPage;
  89. },
  90. transitionsBuilder: (
  91. context,
  92. animation,
  93. secondaryAnimation,
  94. child,
  95. ) =>
  96. Stack(
  97. children: [
  98. SlideTransition(
  99. position: rightDir ? Tween<Offset>(
  100. begin: Offset(0.0, 0.0),
  101. end: Offset(0.0, -1.0),
  102. ).animate(
  103. CurvedAnimation(parent: animation, curve: Curves.easeIn),
  104. ) : Tween<Offset>(
  105. begin: Offset(0.0, 0.0),
  106. end: Offset(0.0, 1.0),
  107. ).animate(
  108. CurvedAnimation(parent: animation, curve: Curves.easeIn),
  109. ),
  110. child: enterPage,
  111. ),
  112. SlideTransition(
  113. position: rightDir ? Tween<Offset>(
  114. begin: Offset(0.0, 1.0),
  115. end: Offset.zero,
  116. ).animate(
  117. CurvedAnimation(parent: animation, curve: Curves.easeInOut),
  118. ) : Tween<Offset>(
  119. begin: Offset(0.0, -1.0),
  120. end: Offset.zero,
  121. ).animate(
  122. CurvedAnimation(parent: animation, curve: Curves.easeInOut),
  123. ),
  124. child: exitPage,
  125. )
  126. ],
  127. ),
  128. );
  129. }