在CustomeScrollView
嵌套使用flutter_swiper遇到了这么个问题:
当从服务器端获取的banner数量改变时,会出现
Bad state: No element
和_positions.isNotEmpty
的报错
解决方法:
给Swiper设置key
Swiper(
key: ValueKey(ListUtils.size(mBanners)),
itemBuilder: (BuildContext context, int index) {
return buildBannerItem(index);
},
itemCount: ListUtils.size(mBanners),
...
)
thanks:
https://github.com/best-flutter/flutter_swiper/issues/64
https://www.jianshu.com/p/fc88c0774078
https://api.flutter.dev/flutter/foundation/Key-class.html