给定一个滚动了一些偏移量的 ListView,我如何知道当前视图中的第一个和最后一个项目的索引号?
我试过这个:
class MySliverChildBuilderDelegate extends SliverChildBuilderDelegate {
MySliverChildBuilderDelegate(IndexedWidgetBuilder builder, {int childCount})
: super(builder, childCount: childCount);
@override
void didFinishLayout(int firstIndex, int lastIndex) {
print("firstIndex = $firstIndex / lastIndex = $lastIndex");
}
}
接着:
SliverChildBuilderDelegate childrenDelegate =
MySliverChildBuilderDelegate(itemBuilder, childCount: childCount);
ListView.custom(
controller: _controller,
childrenDelegate: childrenDelegate));
但是那些 firstIndex 和 lastIndex 实际上并不是我所认为的......