Line data Source code
1 : import 'package:flutter/cupertino.dart';
2 : import 'package:flutter/material.dart';
3 : import 'transitions_component.dart';
4 :
5 : class LeftToRightFadeTransition extends TransitionInterface {
6 0 : LeftToRightFadeTransition({
7 : TransitionComponent transitionComponent,
8 0 : }) : super(transitionComponent: transitionComponent);
9 :
10 0 : @override
11 : Widget buildChildWithTransition(
12 : BuildContext context,
13 : Curve curve,
14 : Alignment alignment,
15 : Animation<double> animation,
16 : Animation<double> secondaryAnimation,
17 : Widget child) {
18 0 : return SlideTransition(
19 0 : position: Tween<Offset>(
20 : begin: const Offset(-1.0, 0.0),
21 : end: Offset.zero,
22 0 : ).animate(animation),
23 0 : child: FadeTransition(
24 : opacity: animation,
25 0 : child: SlideTransition(
26 0 : position: Tween<Offset>(
27 : begin: Offset.zero,
28 : end: const Offset(1.0, 0.0),
29 0 : ).animate(secondaryAnimation),
30 : child: child),
31 : ),
32 : );
33 : }
34 : }
35 :
36 : class RightToLeftFadeTransition extends TransitionInterface {
37 0 : RightToLeftFadeTransition({
38 : TransitionComponent transitionComponent,
39 0 : }) : super(transitionComponent: transitionComponent);
40 :
41 0 : @override
42 : Widget buildChildWithTransition(
43 : BuildContext context,
44 : Curve curve,
45 : Alignment alignment,
46 : Animation<double> animation,
47 : Animation<double> secondaryAnimation,
48 : Widget child) {
49 0 : return SlideTransition(
50 0 : position: Tween<Offset>(
51 : begin: const Offset(1.0, 0.0),
52 : end: Offset.zero,
53 0 : ).animate(animation),
54 0 : child: FadeTransition(
55 : opacity: animation,
56 0 : child: SlideTransition(
57 0 : position: Tween<Offset>(
58 : begin: Offset.zero,
59 : end: const Offset(-1.0, 0.0),
60 0 : ).animate(secondaryAnimation),
61 : child: child),
62 : ),
63 : );
64 : }
65 : }
66 :
67 : class NoTransition extends TransitionInterface {
68 0 : NoTransition({
69 : TransitionComponent transitionComponent,
70 0 : }) : super(transitionComponent: transitionComponent);
71 :
72 0 : @override
73 : Widget buildChildWithTransition(
74 : BuildContext context,
75 : Curve curve,
76 : Alignment alignment,
77 : Animation<double> animation,
78 : Animation<double> secondaryAnimation,
79 : Widget child) {
80 0 : return transitionComponent.buildChildWithTransition(
81 : context, curve, alignment, animation, secondaryAnimation, child);
82 : }
83 : }
84 :
85 : class FadeInTransition extends TransitionInterface {
86 1 : FadeInTransition({
87 : TransitionComponent transitionComponent,
88 1 : }) : super(transitionComponent: transitionComponent);
89 :
90 1 : @override
91 : Widget buildChildWithTransition(
92 : BuildContext context,
93 : Curve curve,
94 : Alignment alignment,
95 : Animation<double> animation,
96 : Animation<double> secondaryAnimation,
97 : Widget child) {
98 1 : return FadeTransition(
99 : opacity: animation,
100 2 : child: transitionComponent.buildChildWithTransition(
101 : context, curve, alignment, animation, secondaryAnimation, child),
102 : );
103 : }
104 : }
105 :
106 : class SlideDownTransition extends TransitionInterface {
107 0 : SlideDownTransition({
108 : TransitionComponent transitionComponent,
109 0 : }) : super(transitionComponent: transitionComponent);
110 :
111 0 : @override
112 : Widget buildChildWithTransition(
113 : BuildContext context,
114 : Curve curve,
115 : Alignment alignment,
116 : Animation<double> animation,
117 : Animation<double> secondaryAnimation,
118 : Widget child) {
119 0 : return SlideTransition(
120 0 : position: Tween<Offset>(
121 0 : begin: Offset(0.0, 1.0),
122 : end: Offset.zero,
123 0 : ).animate(animation),
124 0 : child: transitionComponent.buildChildWithTransition(
125 : context, curve, alignment, animation, secondaryAnimation, child),
126 : );
127 : }
128 : }
129 :
130 : class SlideLeftTransition extends TransitionInterface {
131 0 : SlideLeftTransition({
132 : TransitionComponent transitionComponent,
133 0 : }) : super(transitionComponent: transitionComponent);
134 :
135 0 : @override
136 : Widget buildChildWithTransition(
137 : BuildContext context,
138 : Curve curve,
139 : Alignment alignment,
140 : Animation<double> animation,
141 : Animation<double> secondaryAnimation,
142 : Widget child) {
143 0 : return SlideTransition(
144 0 : position: Tween<Offset>(
145 0 : begin: Offset(-1.0, 0.0),
146 : end: Offset.zero,
147 0 : ).animate(animation),
148 0 : child: transitionComponent.buildChildWithTransition(
149 : context, curve, alignment, animation, secondaryAnimation, child),
150 : );
151 : }
152 : }
153 :
154 : class SlideRightTransition extends TransitionInterface {
155 0 : SlideRightTransition({
156 : TransitionComponent transitionComponent,
157 0 : }) : super(transitionComponent: transitionComponent);
158 :
159 0 : @override
160 : Widget buildChildWithTransition(
161 : BuildContext context,
162 : Curve curve,
163 : Alignment alignment,
164 : Animation<double> animation,
165 : Animation<double> secondaryAnimation,
166 : Widget child) {
167 0 : return SlideTransition(
168 0 : position: Tween<Offset>(
169 0 : begin: Offset(1.0, 0.0),
170 : end: Offset.zero,
171 0 : ).animate(animation),
172 0 : child: transitionComponent.buildChildWithTransition(
173 : context, curve, alignment, animation, secondaryAnimation, child),
174 : );
175 : }
176 : }
177 :
178 : class SlideTopTransition extends TransitionInterface {
179 0 : SlideTopTransition({
180 : TransitionComponent transitionComponent,
181 0 : }) : super(transitionComponent: transitionComponent);
182 :
183 0 : @override
184 : Widget buildChildWithTransition(
185 : BuildContext context,
186 : Curve curve,
187 : Alignment alignment,
188 : Animation<double> animation,
189 : Animation<double> secondaryAnimation,
190 : Widget child) {
191 0 : return SlideTransition(
192 0 : position: Tween<Offset>(
193 0 : begin: Offset(0.0, -1.0),
194 : end: Offset.zero,
195 0 : ).animate(animation),
196 0 : child: transitionComponent.buildChildWithTransition(
197 : context, curve, alignment, animation, secondaryAnimation, child),
198 : );
199 : }
200 : }
201 :
202 : class ZoomInTransition extends TransitionInterface {
203 0 : ZoomInTransition({
204 : TransitionComponent transitionComponent,
205 0 : }) : super(transitionComponent: transitionComponent);
206 :
207 0 : @override
208 : Widget buildChildWithTransition(
209 : BuildContext context,
210 : Curve curve,
211 : Alignment alignment,
212 : Animation<double> animation,
213 : Animation<double> secondaryAnimation,
214 : Widget child) {
215 0 : return ScaleTransition(
216 : scale: animation,
217 0 : child: transitionComponent.buildChildWithTransition(
218 : context, curve, alignment, animation, secondaryAnimation, child),
219 : );
220 : }
221 : }
222 :
223 : class SizeTransitions extends TransitionInterface {
224 0 : SizeTransitions({
225 : TransitionComponent transitionComponent,
226 0 : }) : super(transitionComponent: transitionComponent);
227 :
228 0 : @override
229 : Widget buildChildWithTransition(
230 : BuildContext context,
231 : Curve curve,
232 : Alignment alignment,
233 : Animation<double> animation,
234 : Animation<double> secondaryAnimation,
235 : Widget child) {
236 0 : return Align(
237 : alignment: Alignment.center,
238 0 : child: SizeTransition(
239 0 : sizeFactor: CurvedAnimation(
240 : parent: animation,
241 : curve: curve,
242 : ),
243 : child: child,
244 : ),
245 : );
246 : }
247 : }
248 :
249 : class CupertinoTransitions extends TransitionInterface {
250 0 : CupertinoTransitions({
251 : TransitionComponent transitionComponent,
252 0 : }) : super(transitionComponent: transitionComponent);
253 :
254 0 : @override
255 : Widget buildChildWithTransition(
256 : BuildContext context,
257 : Curve curve,
258 : Alignment alignment,
259 : Animation<double> animation,
260 : Animation<double> secondaryAnimation,
261 : Widget child) {
262 0 : return CupertinoPageTransition(
263 : primaryRouteAnimation: animation,
264 : secondaryRouteAnimation: secondaryAnimation,
265 : linearTransition: true,
266 : child: child,
267 : );
268 : }
269 : }
270 :
271 : abstract class TransitionInterface implements TransitionComponent {
272 : TransitionComponent transitionComponent;
273 1 : TransitionInterface({this.transitionComponent});
274 : }
|