You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter实现屏幕底部渐隐效果遇滚动问题求助

Flutter 实现底部渐隐遮罩同时保留ListView滚动功能

你遇到的问题是因为Stack中上层的Container会拦截触摸手势,导致下层的ListView无法响应滚动操作。解决这个问题最简单的方式是用IgnorePointer组件包裹渐变Container,让它不接收任何触摸事件,这样下层的ListView就能正常滚动了。

修改后的代码如下:

Stack(
  children: <Widget>[
    const TodosList(),
    Align(
      alignment: AlignmentDirectional.bottomCenter,
      child: IgnorePointer(
        child: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: <Color>[
                Colors.white.withOpacity(0),
                Colors.white.withOpacity(1),
              ],
            ),
          ),
          width: double.infinity,
          height: 300,
        ),
      ),
    ),
  ],
)

如果后续你需要渐变遮罩随列表滚动自然衔接(比如列表滚动到底部时,遮罩覆盖在列表末尾),也可以考虑在ListView.builder的itemBuilder中,为最后一项添加渐变容器,但这种场景更适合内容联动的需求,你当前固定在屏幕底部的遮罩需求,用IgnorePointer的方案就足够解决问题。

内容的提问来源于stack exchange,提问作者EmanuelLamba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 20:45:36