文章目录
背景
最近在使用Flutter进行业务开发,使用fish-redux进行页面开发中使用了ListView的嵌套,在滑动中会导致竖向滑动冲突。
另外还有个问题, listview在使用的时候需要给个高度, 如果需要根据内容显示自适应高度,也需要进行处理,否则就无法展示list列表内容。
知识点
解决以上两个问题主要用到了Flutter组件Listview的两个属性,分别是:
ScrollPhysics physics,
bool shrinkWrap = false,
shrinkWrap
先说这个字段,默认是flase,就是说listview在使用的过程中,需要指定一个固定高度值,或者占据最大高度, 必须要有个边界范围,否则内容无法展示,在listview的源码中也有相关解释。
/// Whether the extent of the scroll view in the [scrollDirection] should be
/// determined by the contents being viewed.
///
/// If the scroll view does not shrink wrap, then the scroll view will expand
/// to the maximum allowed size in the [scrollDirection]. If the scroll view
/// has unbounded constraints in the [scrollDirection], then [shrinkWrap] must
/// be true.
///
/// Shrink wrapping the content of the scroll view is significantly more
/// expensive than expandi

本文介绍了在Flutter开发中遇到的ListView嵌套滑动冲突及自适应高度问题。通过设置ListView的`shrinkWrap`为true和`physics`为`NeverScrollableScrollPhysics()`,可以避免滑动冲突并实现内容自适应高度。同时,提供了完整的代码示例来解决这些问题。
最低0.47元/天 解锁文章
2479

被折叠的 条评论
为什么被折叠?



