Created
April 12, 2020 07:05
-
-
Save uni-3/258ba76e2f70124022ae24ab5304fe99 to your computer and use it in GitHub Desktop.
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
//refer https://flutter.dev/docs/development/ui/animations/tutorial | |
import 'dart:ui'; | |
import 'package:flutter/animation.dart'; | |
import 'package:flutter/material.dart'; | |
void main() => runApp(LogoApp()); | |
class LogoApp extends StatefulWidget { | |
_LogoAppState createState() => _LogoAppState(); | |
} | |
class _LogoAppState extends State<LogoApp> with SingleTickerProviderStateMixin { | |
Animation<double> animation; | |
AnimationController controller; | |
@override | |
void initState() { | |
super.initState(); | |
controller = | |
AnimationController(duration: const Duration(seconds: 2), vsync: this); | |
animation = CurvedAnimation(parent: controller, curve: Curves.easeIn) | |
..addStatusListener((status) { | |
if (status == AnimationStatus.completed) { | |
controller.reverse(); | |
} else if (status == AnimationStatus.dismissed) { | |
controller.forward(); | |
} | |
}) | |
..addStatusListener((state) => print('$state')); | |
controller.forward(); | |
} | |
@override | |
Widget build(BuildContext context) => GrowTransition( | |
child: LogoWidget(), | |
animation: animation, | |
); | |
@override | |
void dispose() { | |
controller.dispose(); | |
super.dispose(); | |
} | |
} | |
class LogoWidget extends StatelessWidget { | |
// Leave out the height and width so it fills the animating parent | |
Widget build(BuildContext context) => Container( | |
margin: EdgeInsets.symmetric(vertical: 10), | |
child: FlutterLogo(), | |
); | |
} | |
class GrowTransition extends StatelessWidget { | |
// constructor | |
// set classs val by args | |
GrowTransition({this.child, this.animation}); | |
final Widget child; | |
final Animation<double> animation; | |
// Make the Tweens static because they don't change. | |
static final _opacityTween = Tween<double>(begin: 0.1, end: 1); | |
static final _sizeTween = Tween<double>(begin: 0, end: 300); | |
// declare animation and child(logo widget) | |
Widget build(BuildContext context) => Center( | |
child: Opacity( | |
opacity: _opacityTween.evaluate(animation), | |
child: AnimatedBuilder( | |
animation: animation, | |
builder: (context, child) => Container( | |
color: Colors.lightBlue[200], | |
height: _sizeTween.evaluate(animation), | |
width: _sizeTween.evaluate(animation), | |
//height: animation.value, | |
//width: animation.value, | |
child: child, | |
), | |
child: child), | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment