SliverOpacity
子控件为sliver
组件,通常取0.0到1.0值之前,可设置子组件透明度。
与Opacity
属性相同,但是Opacity
是对widget
,SliverOpacity
针对sliver
。
构造函数:
const SliverOpacity({
super.key,
required this.opacity,透明度 ,从 0.0 ~ 1.0
this.alwaysIncludeSemantics = false,
Widget? sliver,
})
例子:
import 'package:flutter/material.dart';
class SliverOpacityPage extends StatefulWidget {
const SliverOpacityPage({Key? key}) : super(key: key);
@override
State<SliverOpacityPage> createState() => _SliverOpacityPageState();
}
class _SliverOpacityPageState extends State<SliverOpacityPage> {
bool _isVisible = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('SliverOpacity'),),
body: CustomScrollView(
slivers: [
SliverOpacity(
opacity: _isVisible ? 1 : 0,
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(context,index){
return Container(
alignment: Alignment.center,
color: Colors.primaries[index % Colors.primaries.length],
height: 100,
child: IconButton(
onPressed: (){
setState(() {
_isVisible = !_isVisible;
});
},
icon: const Icon(Icons.flip),
tooltip: '点击隐藏',
),
);
},
childCount: 10,
),
),
),
],
),
);
}
}