@@ -32,54 +32,80 @@ class AnimatedBoxWidget extends StatelessWidget {
32
32
child: Align (
33
33
alignment: Alignment .center,
34
34
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
-
45
35
/// 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),
53
38
54
39
/// 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),
62
48
63
49
/// 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),
69
51
70
52
/// 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),
78
54
},
79
55
),
80
56
);
81
57
},
82
58
);
83
59
});
84
60
}
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);
85
111
}
0 commit comments