使用分帧插件:keframe
1.在pubspec.yaml中导入插件:keframe: ^2.0.6
2.使用:
1)在需要分帧的页面引入
import 'package:keframe/keframe.dart';
2)布局:
ListView用SizeCacheWidget包裹,ListView的itemView用FrameSeparateWidget包裹
RefreshController _refreshController = RefreshController();
_smartView(){
return SizeCacheWidget(
child: SmartRefresher(
controller: _refreshController,
footer: defaultRefreshFooter(),
enablePullDown: true,
enablePullUp: true,
onRefresh: (){
getSubDataRefresh();
},
onLoading: (){
getSubDataLoadMore();
},
child: ListView.builder(
itemCount: _list.length,
//shrinkWrap: true, 设置自动收缩包裹为true ListView的复用机制不会生效
itemBuilder: (contextList, index) {
return FrameSeparateWidget(
child: _itemView(_list[index], index),
);
}),
),
);
}
_itemView(DataMOdel model, int index){
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.w)),
child: ClipRRect(
borderRadius: BorderRadius.circular(20.w),
child: CachedNetworkImage(
imageUrl: model.itemPic,
width: 120.w,
height: 120.w,
fit: BoxFit.cover),
))
}