Closed yyong37 closed 7 months ago
sliver
的下标无法直接拿到,需要你自己记录与维护一个 Map<BuildContext, int>
,存储的内容为:{sliverCtx : index}
,再结合 onObserveViewport
回调可以获取当前的第一个 sliverCtx
,通过这种方式可以间接拿到索引。
谢谢你的解答。我现在按照你说的在onObserveViewPort中没有任何输出,是我忽略了什么东西吗?
SliverViewObserver(
controller: sliverObserverController,
sliverContexts: () => contextList,
// this line
onObserveViewport: (result) {
final firstChildCtxInViewport = result.firstChild.sliverContext;
debugPrint('first child ctx-- $firstChildCtxInViewport');
},
child: CustomScrollView(......)
很有可能是你传入的 sliverContexts
用的不是最外层的 sliver
相关说明:1.3、onObserveViewport 回调
建议你用两个 SliverViewObserver
,一个负责观察 item
,另一个负责观察 sliver
,这样也能区分开 sliverContexts
Platforms
dart
Description
example:multi_sliver_demo_page
请问在该示例中,我该如何获取section的索引?
My code
No response
Try do it
No response