我使用的是一个带无限分页的提供者模式。问题是每当调用一个函数来获取整个小部件重建过程中的数据时。
class Xyz extends StatelessWidget {
Xyz({Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
AlbumNewProvider ap = Provider.of<AlbumNewProvider>(context);
ap.fetchMore();
return Scaffold(
body: ap.albumList.isNotEmpty
? ListView.builder(
itemCount: ap.albumList.length,
itemBuilder: (BuildContext context, int index) {
if (ap.loading != LoadingState.loading && index > (ap.albumList.length * 0.9)) ap.fetchMore();
return albumItem(context, ap.albumList[index]);
},
)
: Center(child: Text('No record found')),
);
}
}
ap.fetchMore()
Future<void> fetchMore() async {
if (loading != LoadingState.loading) {
loading = LoadingState.loading;
var itemModel = await _service.fetchList(albumFetcher.currentPage);
await albumList.addAll(itemModel.values);
await itemModel.values.clear();
itemModel.addCurrentPage();
albumFetcher = itemModel;
}
loading = LoadingState.done;
notifyListeners();
}
如何避免重新构建整个小部件,我正在尝试跳过StatefulWidget
。
发布于 2021-05-09 14:34:37
我错过了这个概念,整个“构建”函数在每次调用notifyListeners()
时都会调用。
https://stackoverflow.com/questions/65531906
复制相似问题