Flutter 滚动控制器如何工作,它们如何执行
Flutter :我是 flutter 的新手,我想知道它们在幕后如何工作(当我们将滚动控制器附加到可滚动小部件时实际会发生什么。)。我阅读了文档,但我很难理解。
controller: ** _controller **,
scrollDirection: Axis.vertical,
child: Wrap(
// direction: Axis.horizontal,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4.0,
runSpacing: 4.0,
children: *MY WIDGET*,
),```
Flutter : i am new to flutter , i wanted to know how do they work behind the scenes(what actually happens when we attach a scroll controller to a scrollable widget.) . i read the docs but its hard for me to understand.
controller: ** _controller **,
scrollDirection: Axis.vertical,
child: Wrap(
// direction: Axis.horizontal,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 4.0,
runSpacing: 4.0,
children: *MY WIDGET*,
),```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个很好的问题,也是我很好奇的问题。如果您使用
ListView
,它会子类化另一个名为BoxScrollView
的类,而该类本身又是ScrollView
的子类,实际上是ScrollView
如果您查看以下代码,它会保留ScrollController
实例:如果您查看
ScrollView
的build()
函数,您会看到这颗宝石:你看到了将
controller
作为参数的Scrollable
实例?我不会粘贴更多代码,因为它可能会很长,但我建议您继续查看
Scrollablle
和ScrollView
的源代码以获取更好地了解它们的工作原理。This is a good question and something I was curious about as well. If you're using
ListView
, it subclasses another class calledBoxScrollView
which itself subclassesScrollView
and it's in factScrollView
that holds onto theScrollController
instance if you look at this code:If you then look in the
build()
function ofScrollView
you'll see this gem:You see the
Scrollable
instance which takes thecontroller
in as a parameter?I'm not going to paste more code since it can get quite long but I suggest that you go ahead and look at the source code for
Scrollablle
and alsoScrollView
to get a better understanding of how they work.