可容纳一个子组件,并使其进行透明度渐变动画,需要提供动画器opacity。
相关组件
FadeTransition基本使用
<br />【child】 : 孩子组件 【Widget】<br />【opacity】 : 动画 【Animation<double>】<br />![193.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589508542272-9c7844a9-4a00-46b1-9803-5878d23c5c80.gif#align=left&display=inline&height=120&margin=%5Bobject%20Object%5D&name=193.gif&originHeight=120&originWidth=397&size=71216&status=done&style=none&width=397)
import 'package:flutter/material.dart';
class CustomFadeTransition extends StatefulWidget {
@override
_CustomFadeTransitionState createState() => _CustomFadeTransitionState();
}
class _CustomFadeTransitionState extends State<CustomFadeTransition>
with SingleTickerProviderStateMixin {
AnimationController _ctrl;
@override
void initState() {
_ctrl = AnimationController(vsync: this, duration: Duration(seconds: 2));
_ctrl.forward();
super.initState();
}
@override
void dispose() {
_ctrl.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
_ctrl.reset();
_ctrl.forward();
});
},
child: Container(
color: Colors.grey.withAlpha(22),
width: 100,
height: 100,
child: FadeTransition(
opacity: CurvedAnimation(parent: _ctrl, curve: Curves.linear),
child: Icon(Icons.android, color: Colors.green, size: 60),
),
),
);
}
}