@@ -32,54 +32,80 @@ class AnimatedBoxWidget extends StatelessWidget {
3232 child: Align (
3333 alignment: Alignment .center,
3434 child: switch (animationType) {
35- /// Rotate
36- AnimationType .rotate =>
37- Transform .rotate (angle: animation.value * pi, child: child),
38-
39- /// Scale
40- AnimationType .scale => Transform .scale (
41- scale: animation.value,
42- child: child,
43- ),
44-
4535 /// Translate x
46- AnimationType .translateX => Transform .translate (
47- offset: Tween (
48- begin: Offset ((- constraints.maxWidth + boxSize) / 2 , 0 ),
49- end: Offset ((constraints.maxHeight - boxSize) / 2 , 0 ),
50- ).transform (animation.value),
51- child: child,
52- ),
36+ AnimationType .translateX =>
37+ _buildTransformX (constraints, boxSize, child),
5338
5439 /// Translate Y
55- AnimationType .translateY => Transform .translate (
56- offset: Tween (
57- begin: Offset (0 , (- constraints.maxHeight + boxSize) / 2 ),
58- end: Offset (0 , (constraints.maxHeight - boxSize) / 2 ),
59- ).transform (animation.value),
60- child: child,
61- ),
40+ AnimationType .translateY =>
41+ _buildTransformY (constraints, boxSize, child),
42+
43+ /// Rotate
44+ AnimationType .rotate => _buildRotate (child),
45+
46+ /// Scale
47+ AnimationType .scale => _buildScale (child),
6248
6349 /// Fade
64- AnimationType .fade => AnimatedOpacity (
65- duration: const Duration (milliseconds: 100 ),
66- opacity: animation.value.clamp (0.0 , 1.0 ),
67- child: child,
68- ),
50+ AnimationType .fade => _buildFade (child),
6951
7052 /// Flip
71- AnimationType .flip => Transform (
72- alignment: FractionalOffset .center,
73- transform: Matrix4 .identity ()
74- ..setEntry (2 , 1 , 0.0002 )
75- ..rotateY (animation.value * pi),
76- child: child,
77- ),
53+ AnimationType .flip => _buildFlip (child),
7854 },
7955 ),
8056 );
8157 },
8258 );
8359 });
8460 }
61+
62+ Transform _buildFlip (Widget ? child) {
63+ return Transform (
64+ alignment: FractionalOffset .center,
65+ transform: Matrix4 .identity ()
66+ ..setEntry (2 , 1 , 0.0002 )
67+ ..rotateY (animation.value * pi),
68+ child: child,
69+ );
70+ }
71+
72+ AnimatedOpacity _buildFade (Widget ? child) {
73+ return AnimatedOpacity (
74+ duration: const Duration (milliseconds: 100 ),
75+ opacity: animation.value.clamp (0.0 , 1.0 ),
76+ child: child,
77+ );
78+ }
79+
80+ Transform _buildTransformY (
81+ BoxConstraints constraints, double boxSize, Widget ? child) {
82+ return Transform .translate (
83+ offset: Tween (
84+ begin: Offset (0 , (- constraints.maxHeight + boxSize) / 2 ),
85+ end: Offset (0 , (constraints.maxHeight - boxSize) / 2 ),
86+ ).transform (animation.value),
87+ child: child,
88+ );
89+ }
90+
91+ Transform _buildTransformX (
92+ BoxConstraints constraints, double boxSize, Widget ? child) {
93+ return Transform .translate (
94+ offset: Tween (
95+ begin: Offset ((- constraints.maxWidth + boxSize) / 2 , 0 ),
96+ end: Offset ((constraints.maxHeight - boxSize) / 2 , 0 ),
97+ ).transform (animation.value),
98+ child: child,
99+ );
100+ }
101+
102+ Transform _buildScale (Widget ? child) {
103+ return Transform .scale (
104+ scale: animation.value,
105+ child: child,
106+ );
107+ }
108+
109+ Transform _buildRotate (Widget ? child) =>
110+ Transform .rotate (angle: animation.value * pi, child: child);
85111}
0 commit comments