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
相关产品推荐
相关产品推荐

