Advertisement
Guest User

Untitled

a guest
May 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/animation.dart';
  3.  
  4. void main() {
  5. runApp(new MaterialApp(
  6. home: new MyApp(),
  7. ));
  8. }
  9.  
  10. class MyApp extends StatefulWidget {
  11. @override
  12. _State createState() => new _State();
  13. }
  14.  
  15. class _State extends State<MyApp> with TickerProviderStateMixin {
  16.  
  17. Animation<double> animation;
  18. AnimationController controller;
  19. static final _opacityTween = new Tween<double>(begin: 0.1, end: 1.0);
  20. static final _sizeTween = new Tween<double>(begin: 0.0, end: 300.0);
  21.  
  22. initState() {
  23. super.initState();
  24. controller = new AnimationController(duration: const Duration(milliseconds: 2000), vsync: this);
  25. animation = new CurvedAnimation(parent: controller, curve: Curves.easeIn);
  26. animation.addStatusListener(listener);
  27. controller.forward();
  28.  
  29. }
  30.  
  31. void listener(AnimationStatus status) {
  32. if(status == AnimationStatus.completed) {
  33. controller.reverse();
  34. } else if (status == AnimationStatus.dismissed) {
  35. controller.forward();
  36. }
  37. }
  38.  
  39.  
  40.  
  41. @override
  42. Widget build(BuildContext context) {
  43.  
  44. print(_opacityTween.evaluate(animation));
  45.  
  46. return new Scaffold(
  47. appBar: new AppBar(
  48. title: new Text('Name here'),
  49. ),
  50. body: new Container(
  51. padding: new EdgeInsets.all(32.0),
  52. child: new Center(
  53. child: new Opacity(
  54. opacity: _opacityTween.evaluate(animation),
  55. child: new Container(
  56. margin: new EdgeInsets.symmetric(vertical: 10.0),
  57. height: _sizeTween.evaluate(animation),
  58. width: _sizeTween.evaluate(animation),
  59. child: new FlutterLogo(),
  60. ),
  61. ),
  62. ),
  63. ),
  64. );
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement