Flutter开发listview嵌套滑动冲突问题

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

背景

最近在使用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
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值