@@ -18,66 +18,65 @@ class AnimatedBoxWidget extends StatelessWidget {
18
18
final theme = Theme .of (context).colorScheme;
19
19
20
20
return LayoutBuilder (builder: (context, constraints) {
21
- final boxSize = constraints.maxHeight / 4 ;
21
+ final boxSize = min ( constraints.maxWidth, constraints. maxHeight) / 4 ;
22
22
23
23
return AnimatedBuilder (
24
24
animation: animation,
25
25
child: ColoredBox (
26
26
color: theme.primary,
27
- child: SizedBox (
28
- width: boxSize,
29
- height: boxSize,
30
- ),
27
+ child: SizedBox .square (dimension: boxSize),
31
28
),
32
29
builder: (context, child) {
33
- return Container (
34
- alignment: Alignment .center,
30
+ return ColoredBox (
35
31
color: theme.onPrimaryFixed,
36
- child: switch (animationType) {
37
- /// Rotate
38
- AnimationType .rotate =>
39
- Transform .rotate (angle: animation.value * pi, child: child),
32
+ child: Align (
33
+ alignment: Alignment .center,
34
+ child: switch (animationType) {
35
+ /// Rotate
36
+ AnimationType .rotate =>
37
+ Transform .rotate (angle: animation.value * pi, child: child),
40
38
41
- /// Scale
42
- AnimationType .scale => Transform .scale (
43
- scale: animation.value,
44
- child: child,
45
- ),
39
+ /// Scale
40
+ AnimationType .scale => Transform .scale (
41
+ scale: animation.value,
42
+ child: child,
43
+ ),
46
44
47
- /// Translate x
48
- AnimationType .translateX => Transform .translate (
49
- offset: Tween (
50
- begin: Offset ((- constraints.maxWidth + boxSize) / 2 , 0 ),
51
- end: Offset ((constraints.maxHeight - boxSize) / 2 , 0 ),
52
- ).transform (animation.value),
53
- child: child,
54
- ),
45
+ /// 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
+ ),
55
53
56
- /// Translate Y
57
- AnimationType .translateY => Transform .translate (
58
- offset: Tween (
59
- begin: Offset (0 , (- constraints.maxHeight + boxSize) / 2 ),
60
- end: Offset (0 , (constraints.maxHeight - boxSize) / 2 ),
61
- ).transform (animation.value),
62
- child: child,
63
- ),
54
+ /// 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
+ ),
64
62
65
- /// Fade
66
- AnimationType .fade => Opacity (
67
- // accept values between 0 and 1
68
- opacity: max ( 0 , min ( 1 , animation.value) ),
69
- child: child,
70
- ),
63
+ /// Fade
64
+ AnimationType .fade => AnimatedOpacity (
65
+ duration : const Duration (milliseconds : 100 ),
66
+ opacity: animation.value. clamp ( 0.0 , 1.0 ),
67
+ child: child,
68
+ ),
71
69
72
- /// Flip
73
- AnimationType .flip => Transform (
74
- alignment: FractionalOffset .center,
75
- transform: Matrix4 .identity ()
76
- ..setEntry (2 , 1 , 0.0015 )
77
- ..rotateY (animation.value * pi),
78
- child: child,
79
- ),
80
- },
70
+ /// 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
+ ),
78
+ },
79
+ ),
81
80
);
82
81
},
83
82
);
0 commit comments