Flutter有一的动画引擎很强大, 可以为应用添加任何的效果个动画,但是有些时候,有些效果和动画并不需要那么炫酷,比如淡入淡出.
Flutter同样也提供了很多转场可以加入应用中,比如FadeTransition,FadeTransition可以对Widget进行淡入淡出效果,它只需要一个子项和一个动画.

FadeTransition
FadeTransition
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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();
}
}

代码github