懒加载滚动视图
一个 ScrollView 的包装器,可启用惰性加载。
用法
在你的pubspec.yaml文件中添加lazy_load_scrollview依赖项
dependencies:
lazy_load_scrollview: 1.2.0
在你的Dart代码中,导入package:lazy_load_scrollview/lazy_load_scrollview.dart
然后你可以用LazyLoadScrollView包装你的ListView,GridView,RefreshIndicator等。
确保你添加了一个endOfPageListener,它将在到达列表底部时接收调用。
import 'package:lazy_load_scrollview/lazy_load_scrollview.dart';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: LazyLoadScrollView(
onEndOfPage: () => loadMore(),
child: ListView.builder(
itemCount: data.length,
itemBuilder: (context, position) {
return Text("Position $position");
},
),
),
);
}
类定义
LazyLoadScrollView(
endOfPageListener: () => loadMore(), // The callback when reaching the end of the list
scrollOffset: 100 // Pixels from the bottom that should trigger a callback
child: Widget, // A subclass of `ScrollView`
);