Detect End Of An Animation
Complete Code For Detect End Of An Animation In Flutter
main.dart
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override MyHomePageState createState() { return new MyHomePageState(); } } class MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin { AnimationController animationController; Animation<double> animation; GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); @override void initState() { super.initState(); animationController = AnimationController( vsync: this, duration: Duration(seconds: 5), ) ..addListener(() => setState(() {})); animation = Tween<double>( begin: 50.0, end: 120.0, ).animate(animationController); animationController.forward(); animation.addStatusListener((status) { if (status == AnimationStatus.completed) { scaffoldKey.currentState.showSnackBar(SnackBar( content: Text("Animation has ended"), )); } }); } @override Widget build(BuildContext context) { return Scaffold( key: scaffoldKey, appBar: AppBar( backgroundColor: Colors.cyan, title: Text("Detect End Of An Animation" )), body: Center( child: Container( color: Colors.cyan, height: animation.value, width: animation.value, ), ), ); } }