Loading...
Loading...
Implements animated effects, transitions, and motion in a Flutter app. Use when adding visual feedback, shared element transitions, or physics-based animations.
npx skill4agent add flutter/skills flutter-animating-appsAnimationAnimation<T>AnimationControllervsyncSingleTickerProviderStateMixindispose()Tween<T>ColorOffsetdouble.animate()CurveCurves.easeInCurves.bounceOutCurvedAnimationCurveTweenAnimatedContainerAnimatedOpacityTweenAnimationBuilderAnimationControllerAnimatedBuilderAnimatedWidgetSpringSimulationTweenAnimationControllerIntervalContainerAnimatedContainerdurationcurvesetState()SingleTickerProviderStateMixinTickerProviderStateMixinStateAnimationControllerinitState()vsync: thisdurationTween.animate()AnimatedBuilderAnimatedWidgetAnimationAnimatedBuilderanimationcontroller.forward()controller.reverse()controller.repeat()controller.dispose()dispose()dispose()HerotagHeroHerotagHeroHeroNavigatorAnimationControllerGestureDetectoronPanEndDragEndDetailsSpringSimulationcontroller.animateWith(simulation)class StaggeredAnimationDemo extends StatefulWidget {
State<StaggeredAnimationDemo> createState() => _StaggeredAnimationDemoState();
}
class _StaggeredAnimationDemoState extends State<StaggeredAnimationDemo> with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<double> _widthAnimation;
late Animation<Color?> _colorAnimation;
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
);
// Staggered width animation (0.0 to 0.5 interval)
_widthAnimation = Tween<double>(begin: 50.0, end: 200.0).animate(
CurvedAnimation(
parent: _controller,
curve: const Interval(0.0, 0.5, curve: Curves.easeIn),
),
);
// Staggered color animation (0.5 to 1.0 interval)
_colorAnimation = ColorTween(begin: Colors.blue, end: Colors.red).animate(
CurvedAnimation(
parent: _controller,
curve: const Interval(0.5, 1.0, curve: Curves.easeOut),
),
);
_controller.forward();
}
void dispose() {
_controller.dispose(); // CRITICAL: Prevent memory leaks
super.dispose();
}
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: _controller,
builder: (context, child) {
return Container(
width: _widthAnimation.value,
height: 50.0,
color: _colorAnimation.value,
);
},
);
}
}Route createCustomRoute(Widget destination) {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => destination,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(0.0, 1.0); // Start from bottom
const end = Offset.zero;
const curve = Curves.easeOut;
final tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
final offsetAnimation = animation.drive(tween);
return SlideTransition(
position: offsetAnimation,
child: child,
);
},
);
}
// Usage: Navigator.of(context).push(createCustomRoute(const NextPage()));