flutter_swiper
flutter_swiper copied to clipboard
每一次切换都会重新加载图片?
图片是网络获取的。每一次切换都会重新加载图片?很难受啊老哥 有什么解决办法或者设置属性吗 没看到啊
child: new Swiper(
outer: false,
loop: false,
controller: swiperController,
itemBuilder: (context, index) {
final item = widget.previewImg[index];
return Wrap(
children: item.map((i) {
return Container(
margin: EdgeInsets.only(
right: ScreenUtil().setWidth(8),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(
ScreenUtil().setWidth(10),
),
child: Image.network(
i,
width: ScreenUtil().setWidth(64),
height: ScreenUtil().setWidth(64),
fit: BoxFit.cover,
),
),
);
}).toList(),
);
},
itemCount: 2,
),
每一次切换 itemBuilder肯定会被重新执行的,就算是PageView也是一样的 。
另外,如果你把Loop修改为true的话,虽然看起来能做到循环切换图片,实际上每个item的页面状态不会被保留,页面总是会被重新初始化,这是Swiper组件的一个bug 。
这需要修改PageView内部源代码才能做到这一点。
就像下面代码一样,如果你需要,你可以进入PageView的build函数内部,按照下面的方式进行修改即可:
看这个例子: https://github.com/ModWU/flutter_code_manager
这个怎么解决啊 我有3个card 每个card显示 一个 chart 现在切换 每次都要重新渲染
如果你不开启循环切换图片的功能,那么你只需要with AutomaticKeepAliveClientMixin这个类并修改wantKeepAlive为true即可,否则在flutter循环切换图片无法保证状态,除非用我的那个插件@jiangyh1024
谢谢 我已经用pageview 和keepalive自己写了 放弃swipet
发自我的iPhone
在 2021年5月5日,下午8:12,ModWU @.***> 写道:
如果你不开启循环切换图片的功能,那么你只需要with @.***
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.