Open JDongKhan opened 4 months ago
scrollview_observer
没有提供滚动到指定 sliver
位置的功能,不过你可以通过如下代码实现
final ScrollController _scrollController = ScrollController();
late SliverObserverController observerController;
Map<int, BuildContext> _sliverContextMap = {};
void _incrementCounter() {
final renderObj = ObserverUtils.findRenderObject(_sliverContextMap[8]);
if (renderObj is! RenderSliver) return;
// 动画滚动至下标位置
_scrollController.animateTo(
renderObj.constraints.precedingScrollExtent,
duration: const Duration(seconds: 1),
curve: Curves.ease,
);
}
...
child: CustomScrollView(
controller: _scrollController,
slivers: List.generate(
10,
(index) {
Widget resultWidget = SliverToBoxAdapter(
child: GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (_) => CustomScrollViewDemoPage(),
),
);
},
child: Container(
color: Colors.grey,
margin: const EdgeInsets.all(12),
child: Text(index.toString()),
height: 100,
),
),
);
resultWidget = SliverObserveContext(
onObserve: (ctx) {
_sliverContextMap[index] = ctx;
},
child: resultWidget,
);
return resultWidget;
},
),
),
多谢,我试试。
您好,有些场景不知道如何使用,能帮忙看一下吗? 谢谢。
Platforms
Android, iOS
Description
从demo上都在在解决CustomScrollView里面SliverList和SliverGrid的问题,没有看到有关其他sliver组件的解决方案。
My code
Try do it
这样搞没有效果,还需要额外实现其他方法吗?