flutter3.0学习笔记

SliverOpacity

Preview

SliverOpacity子控件为sliver组件,通常取0.0到1.0值之前,可设置子组件透明度。

Opacity属性相同,但是Opacity是对widgetSliverOpacity针对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,
             ),
           ),
         ),
       ],
     ),
   );
 }
}

黄橙色娱乐综艺视频背景配图动感个人分享抖音视频 (1).gif