ScrollController未附加到任何滚动视图 [英] ScrollController not attached to any scroll views

查看:328
本文介绍了ScrollController未附加到任何滚动视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CustomScrollView,并为其提供控制器. ScrollController可以工作,我什至在其中添加了一个侦听器并打印出滚动视图的位置.

I'm using CustomScrollView, and providing it with a controller. ScrollController works, I even added a listener to it and print out the position of the scroll view.

CustomScrollView(
    controller: _scrollController,

现在,我要做的就是跳到initState()函数中的50.0位置.

Now, all i'm trying to do is jump to position 50.0 inside initState() function.

_scrollController.jumpTo(50.0);

但是,我得到了错误

scrollController未附加到任何滚动视图

scrollController not attached to any scroll views

推荐答案

首先通过使用其hasClients属性来检查scrollController是否附加到滚动视图.

Check if the scrollController is attached to a scroll view by using its hasClients property first.

if (_scrollController.hasClients) 
    _scrollController.jumpTo(50.0);

这篇关于ScrollController未附加到任何滚动视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆