避免将带有透明SliverAppBar的SliverToBoxAdapter重叠
创始人
2024-12-16 07:30:33
0

我们可以通过增加 SliverAppBar 的高度来避免重叠。这里提供三种实现方式。

  1. 将 SliverAppBar 的高度设置为非零值
CustomScrollView(
  slivers: [
    SliverAppBar(
      backgroundColor: Colors.transparent,
      expandedHeight: 200.0, // 增加高度即可
      flexibleSpace: FlexibleSpaceBar(
        title: Text("Title"),
      ),
    ),
    SliverToBoxAdapter(
      child: Container(
        height: 200.0,
        color: Colors.red,
      ),
    ),
  ],
)
  1. 使用 SliverOverlapAbsorber 和 SliverOverlapInjector
DefaultTabController(
  length: 2,
  child: NestedScrollView(
    headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
      return [
        SliverOverlapAbsorber(
          handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
          child: SliverAppBar(
            backgroundColor: Colors.transparent,
            flexibleSpace: FlexibleSpaceBar(
              title: Text("Title"),
            ),
            expandedHeight: 200.0,
            pinned: true,
          ),
        ),
      ];
    },
    body: TabBarView(
      children: [
        SliverOverlapInjector(
          handle:
              NestedScrollView.sliverOverlapAbsorberHandleFor(context), // 这里需要传 handle
          child: SliverToBoxAdapter(
            child: Container(
              color: Colors.red,
              height: 200.0,
            ),
          ),
        ),
        // ...
      ],
    ),
  ),
)
  1. 使用 CustomScrollView 和 SliverOverlapAbsorber
CustomScrollView(
  slivers: [
    SliverOverlapAbsorber(
      handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
      child: SliverAppBar(
        backgroundColor: Colors.transparent,
        flexibleSpace: FlexibleSpaceBar(
          title: Text("Title"),
        ),
        expandedHeight: 200.0,
        pinned: true,
      ),
    ),
    SliverOverlapInjector(
      handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
    ),
    SliverToBoxAdapter(
      child: Container(
        color: Colors.red,
        height: 200.0,
      ),
    ),
  ],
)

相关内容

热门资讯

2分钟了解!科乐吉林麻将有挂吗... 2分钟了解!科乐吉林麻将有挂吗,闲逸免费辅助器,2025新版教程(有挂解说);运科乐吉林麻将有挂吗辅...
6分钟了解!小白大作战外 挂,... 6分钟了解!小白大作战外 挂,新玉海楼茶苑13张有挂吗,可靠教程(有挂教学);1)新玉海楼茶苑13张...
六分钟了解!陕麻圈捉老麻怎么能... 六分钟了解!陕麻圈捉老麻怎么能赢,闲乐游戏辅助工具,黑科技教程(有挂总结);陕麻圈捉老麻怎么能赢是一...
2分钟了解!财神十三张用新号打... 2分钟了解!财神十三张用新号打胜率会高,八闽十三张有外挂吗,可靠教程(有挂机密)1、财神十三张用新号...
6分钟了解!微信海南麻将小程序... 6分钟了解!微信海南麻将小程序插件购买,阳光岛牌乐汇吗,存在挂教程(有挂机密)1、实时微信海南麻将小...
4分钟了解!中州游戏有挂吗,快... 4分钟了解!中州游戏有挂吗,快玩炸翻天辅助功能,揭秘教程(有挂揭秘)一、快玩炸翻天辅助功能软件透明挂...
8分钟了解!新玩乐碣石暗宝有挂... 8分钟了解!新玩乐碣石暗宝有挂吗,途游斗地主修改器,扑克教程(有挂技巧);1、全新机制【新玩乐碣石暗...
六分钟了解!南通长牌app有挂... 六分钟了解!南通长牌app有挂吗,钱塘十三水辅助,解说技巧(有挂攻略)1、每一步都需要思考,不同水平...
9分钟了解!人人烟台麻将有挂吗... 9分钟了解!人人烟台麻将有挂吗,随意玩俱乐部能不能开挂,透牌教程(有挂教程);1、不需要AI权限,帮...
9分钟了解!新猴王有挂吗,中至... 9分钟了解!新猴王有挂吗,中至卧龙有外挂吗,详细教程(有挂透视);1、每一步都需要思考,不同水平的挑...