Created
August 8, 2018 03:16
-
-
Save gliheng/255ca8fcc4ca193eb69568f60ac406bd to your computer and use it in GitHub Desktop.
AnimationController demo
This file contains 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'; | |
import 'radial_logo.dart'; | |
void main() => runApp(new MyApp()); | |
class MyApp extends StatelessWidget { | |
// This widget is the root of your application. | |
@override | |
Widget build(BuildContext context) { | |
return new MaterialApp( | |
title: 'Flutter Demo', | |
theme: new ThemeData( | |
primarySwatch: Colors.blue, | |
accentColor: Colors.red, | |
brightness: Brightness.light, | |
), | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Flutter Demo') | |
), | |
body: AnimationExample() | |
) | |
); | |
} | |
} | |
class AnimationExample extends StatefulWidget { | |
@override | |
_AnimationExampleState createState() => _AnimationExampleState(); | |
} | |
class _AnimationExampleState extends State<AnimationExample> with TickerProviderStateMixin { | |
AnimationController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = AnimationController( | |
vsync: this, duration: Duration(seconds: 5) | |
); | |
controller.addListener(() { | |
setState(() { | |
}); | |
}); | |
} | |
_onTap() { | |
print(controller.status); | |
if (controller.status == AnimationStatus.completed || controller.status == AnimationStatus.forward) { | |
controller.reverse(); | |
} else { | |
controller.forward(); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Center( | |
child: GestureDetector( | |
onTap: _onTap, | |
child: Container( | |
color: Colors.green, | |
width: 100.0 + controller.value * 100.0, | |
height: 100.0 + controller.value * 100.0, | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment