1// ── IMPLICIT ANIMATIONS ──
2// Automatic transitions when values change
3
4AnimatedContainer(
5 duration: const Duration(milliseconds: 500),
6 curve: Curves.easeInOut,
7 width: _expanded ? 300 : 100,
8 height: _expanded ? 200 : 100,
9 decoration: BoxDecoration(
10 color: _expanded ? Colors.blue : Colors.red,
11 borderRadius: BorderRadius.circular(_expanded ? 20 : 50),
12 ),
13 child: const Center(child: Text('Tap me')),
14)
15
16// Other implicit widgets:
17// AnimatedOpacity : fade in/out
18// AnimatedPadding : animate padding
19// AnimatedAlign : animate alignment
20// AnimatedScale : animate scale
21// AnimatedSlide : animate position offset
22// AnimatedSwitcher: cross-fade between widgets
23
24AnimatedSwitcher(
25 duration: const Duration(milliseconds: 300),
26 transitionBuilder: (child, animation) {
27 return ScaleTransition(scale: animation, child: child);
28 },
29 child: Text(
30 '$_counter',
31 key: ValueKey<int>(_counter), // key triggers animation
32 style: const TextStyle(fontSize: 48),
33 ),
34)
35
36// TweenAnimationBuilder: custom implicit animation
37TweenAnimationBuilder<double>(
38 tween: Tween(begin: 0, end: _targetAngle),
39 duration: const Duration(seconds: 1),
40 builder: (context, angle, child) {
41 return Transform.rotate(angle: angle, child: child);
42 },
43 child: const Icon(Icons.refresh, size: 60),
44)