Created
December 23, 2019 17:01
-
-
Save agreensh/a11d71863057260dbdaeb00347a8f4a5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| // This widget is the root of your application. | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Flutter Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| home: MyHomePage(), | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatefulWidget { | |
| @override | |
| _MyHomePageState createState() => _MyHomePageState(); | |
| } | |
| class _MyHomePageState extends State<MyHomePage> | |
| with SingleTickerProviderStateMixin { | |
| AnimationController controller; | |
| void updateState() { | |
| setState(() {}); | |
| } | |
| @override | |
| void initState() { | |
| super.initState(); | |
| controller = | |
| AnimationController(duration: const Duration(milliseconds: 750), vsync: this); | |
| controller.addListener(updateState); | |
| } | |
| @override | |
| void dispose() { | |
| controller.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text('Animating'), | |
| ), | |
| body: Center( | |
| child: FractionallySizedBox( | |
| widthFactor: 0.1 + 0.8 * controller.value, | |
| child: Container( | |
| height: 50, | |
| color: Colors.red, | |
| ), | |
| ), | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: () { | |
| if (controller.isAnimating) { | |
| controller.reset(); | |
| } | |
| if (controller.isCompleted) { | |
| controller.reverse(); | |
| } | |
| else { | |
| controller.forward(); | |
| } | |
| }, | |
| tooltip: 'Animate', | |
| child: Icon(Icons.swap_calls), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment