Loading...
Loading...
Compare original and translation side by side
AnimationAnimation<T>AnimationControllervsyncSingleTickerProviderStateMixindispose()Tween<T>ColorOffsetdouble.animate()CurveCurves.easeInCurves.bounceOutCurvedAnimationCurveTweenAnimationAnimation<T>AnimationControllervsyncSingleTickerProviderStateMixindispose()Tween<T>ColorOffsetdouble.animate()CurveCurvedAnimationCurveTweenCurves.easeInCurves.bounceOutAnimatedContainerAnimatedOpacityTweenAnimationBuilderAnimationControllerAnimatedBuilderAnimatedWidgetSpringSimulationTweenAnimationControllerIntervalAnimatedContainerAnimatedOpacityTweenAnimationBuilderAnimationControllerAnimatedBuilderAnimatedWidgetSpringSimulationAnimationControllerTweenIntervalContainerAnimatedContainerdurationcurvesetState()ContainerAnimatedContainerdurationcurvesetState()SingleTickerProviderStateMixinTickerProviderStateMixinStateAnimationControllerinitState()vsync: thisdurationTween.animate()AnimatedBuilderAnimatedWidgetAnimationAnimatedBuilderanimationcontroller.forward()controller.reverse()controller.repeat()controller.dispose()dispose()dispose()StateSingleTickerProviderStateMixinTickerProviderStateMixininitState()AnimationControllervsync: thisdurationTween.animate()AnimatedBuilderAnimatedWidgetAnimationAnimatedBuilderanimationcontroller.forward()controller.reverse()controller.repeat()dispose()controller.dispose()dispose()HerotagHeroHerotagHeroHeroNavigatorHeroHerotagHeroHerotagHeroNavigatorAnimationControllerGestureDetectoronPanEndDragEndDetailsSpringSimulationcontroller.animateWith(simulation)AnimationControllerGestureDetectoronPanEndDragEndDetailsSpringSimulationcontroller.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()));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,
);
// 交错宽度动画(0.0到0.5时间区间)
_widthAnimation = Tween<double>(begin: 50.0, end: 200.0).animate(
CurvedAnimation(
parent: _controller,
curve: const Interval(0.0, 0.5, curve: Curves.easeIn),
),
);
// 交错颜色动画(0.5到1.0时间区间)
_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(); // 关键:防止内存泄漏
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); // 从底部开始
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,
);
},
);
}
// 使用方式:Navigator.of(context).push(createCustomRoute(const NextPage()));