Flutter有一的动画引擎很强大, 可以为应用添加任何的效果个动画,但是有些时候,有些效果和动画并不需要那么炫酷,比如淡入淡出.
Flutter同样也提供了很多转场可以加入应用中,比如FadeTransition,FadeTransition可以对Widget进行淡入淡出效果,它只需要一个子项和一个动画.
import 'package:flutter/material.dart';
class GoogleFadeTransition extends StatefulWidget {
@override
GoogleFadeTransitionState createState() => new GoogleFadeTransitionState();
}
class GoogleFadeTransitionState extends State<GoogleFadeTransition> with SingleTickerProviderStateMixin{
AnimationController _controller;
Animation _animation;
@override
Widget build(BuildContext context) {
_controller.forward();
return FadeTransition(
child: Container(
color: Colors.red,
width: 200.0,
height: 200.0,
),
opacity: _animation,
);
}
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: Duration(seconds: 2),
);
_animation = Tween(
begin: 0.0,
end: 1.0,
).animate(_controller);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}