Pause Animation
Complete Code For In Pause Animation 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,
home: MyHomePage()
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
AnimationController animationController;
Animation<double> animation;
bool _isPlaying = true;
@override
void initState() {
super.initState();
animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 5),
)
..addListener(() => setState(() {}))
..repeat();
animation = Tween<double>(
begin: 50.0,
end: 120.0,
).animate(animationController);
animationController.forward();
}
@override
void dispose() {
animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.red[700],
title: Text("Pause Animation")),
body: Column(
children: <Widget>[
Expanded(
child: Center(
child: Container(
height: animation.value,
width: animation.value,
child: FlutterLogo(),
),
),
),
RaisedButton(
child: Text(_isPlaying ? "Pause Animation" : "Play Animation",style: TextStyle(color: Colors.white),),
color: Colors.red[700],
onPressed: () {
_isPlaying
? animationController.reset()
: animationController.repeat();
}),
],
),
);
}
}