可容纳一个子组件,将其透明度变为opacity值, opacity在0~1之间。
相关组件
Opacity基本使用
<br />【child】 : 孩子组件 【Widget】<br />【opacity】 : 透明度0~1 【double】<br />![187.gif](https://cdn.nlark.com/yuque/0/2020/gif/326147/1589507779204-a854a641-5f3e-424a-90fe-a937a2d9f8cc.gif#align=left&display=inline&height=217&margin=%5Bobject%20Object%5D&name=187.gif&originHeight=217&originWidth=397&size=401945&status=done&style=none&width=397)
import 'package:flutter/material.dart';
class CustomOpacity extends StatefulWidget {
@override
_CustomOpacityState createState() => _CustomOpacityState();
}
class _CustomOpacityState extends State<CustomOpacity> {
var _opacity = 0.2;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[_buildSlider(), _buildOpacity()],
);
}
// 创建Opacity
Widget _buildOpacity() => Opacity(
opacity: _opacity,
child: Image.asset(// 图片
'assets/images/icon_head.png',
width: 100,
),
);
Widget _buildSlider() => Slider(
divisions: 20,
label: _opacity.toString(),
value: _opacity,
onChanged: (v) => setState(() => _opacity = v));
}