Photo by Zoltan Tasi on Unsplash

In our previous section we've seen how we can create a Scrollbar. We have also seen how we can read about other Scrolling Widgets. A Scrollbar always belongs to the Scrolling widgets category. And there are more you may have interest in.

At the end of this post we'll provide you a list of other Scrolling Widgets.

When we say that a Scrollbar is interactive, actually what does that mean?

Let's try to understand that concept first. Why so? Because we've seen in our previous section that a Scrollbar thumb can be dragged along the main axis of the ScrollView to change the ScrollPosition.

If we tap along the track where the Scrollbar thumb operates, it will trigger a ScrollIncrementType.page based on the relative position to the thumb. In addition, a Scrollbar, due to its interactive nature, can use the PrimaryScrollController if a controller is not set.

Moreover, if we can provide a unique ScrollController to each Scrollable, we can prevent multiple ScrollPositions being attached to the PrimaryScrollController.

In our previous Scrollbar example we've seen how a Scrollbar's ScrollView.scrollDirection of Axis.vertical automatically attaches its ScrollPosition to the PrimaryScrollController. It takes place because we've not provided a ScrollController.

Scrollbar in flutter
Scrollbar in flutter

What is the role of ScrollController in a Scrollbar?

When we say a Scrollbar is interactive, it directly has a link to the State of the object. In fact, to be more precise, we can say that each scroll controller is stored as member variable in State objects.

Why?

Because they can be reused in each State.build. Therefore, a ScrollController actually controls a scrollable widget.

As a result, we can subsequently confirm that a ScrollController creates a ScrollPosition to manage the state specific to an individual Scrollable widget. Consequently, a ScrollController always notifies its listeners whenever a user scrolls and the ScrollPosition changes.

To understand this concept let's see the screenshots firstly.

Scrollbar controller sample one
Scrollbar controller sample one

The above image shows us a column and inside that column we have two scrollable widgets.

Watch the first Scrollbar code.

Further Reading >>


This free site is ad-supported. Learn more