Reputation: 2910
Some widgets like ListView accept a controller.
but I don't know why for example a controller can update the scroll position by calling controller.animateTo()
without calling setState
?
it is a little strange to me what exactly a controller is? (I know that a controller can be used to customize the behavior of a widget)
and What's going on inside a controller?
Upvotes: 0
Views: 1482
Reputation: 277517
They don't.
Controllers do not make widgets rebuild. They only provide a way to listen to changes (usually through ChangeNotifier
/ValueNotifier
)
It is then another widget that uses this listen mechanism to call setState.
One example would be AnimatedBuilder
. It's a stateful widget that calls setState
when animation
emits some notifications
Upvotes: 4