Skip to content

Instantly share code, notes, and snippets.

@gliheng
Created August 8, 2018 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gliheng/255ca8fcc4ca193eb69568f60ac406bd to your computer and use it in GitHub Desktop.
Save gliheng/255ca8fcc4ca193eb69568f60ac406bd to your computer and use it in GitHub Desktop.
AnimationController demo
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