ScrollPhysics in Flutter!

Abhishek Doshi
3 min readAug 1, 2021

--

Using ListView or PageView variants? How about changing the nature of the scroll in it so that your users can feel more real while using it? Let’s see how you can do that using different ScrollPhysics.

Image copyright to respective owner.

So if you are using any widget which has scrolling functionality, like ListView, ListView.builder, ListView.separated, PageView, PageView.builder, SingleChildScrollView, etc., you will get a parameter inside it called physics which takes up a ScrollPhysics . This parameter defines how users will see the scroll of your widget. Let’s see each type of ScrollPhysics one by one!

1. NeverScrollableScrollPhysics:

This physics will disable the scroll of your widget completely. It will render a non-scrollable list.

2. BouncingScrollPhysics:

This physics gives a bouncing effect when a user reaches the end of the list. This physics is also a bit smoother to scroll compared to other types of physics. A similar effect is used in iOS. Tip: If you wish to have a less bounce effect, you can go into the code of BouncingScrollPhysics and make changes in the offset parameter. If you decrease the value of offset , the space behind the list when the bounce effect comes will decrease and hence you will feel like the bounce effect is less compared to earlier.

3. ClampingScrollPhysics:

This physics basically stops the list when the user reaches the end and shows a glow to indicate it. You can definitely remove the glow if you wish using ScrollConfiguration. This is the default scroll for Android. This scroll may sometimes feel a little choppy.

4. FixedExtentScrollPhysics:

This physics is somewhat different from others. If you use this with ListView or PageView, you will notice your scroll lags a lot. FixedExtentScrollPhysics only scrolls to items instead of any offset in between. This is usually used with FixedExtendScrollControllers and the widget that use them. Most commonly, FixedExtentScrollPhysics is used with ListWheelScrollView which gives a wheel kind of effect when used with FixedExtentScrollPhysics.

FixedExtentScrollPhysics with ListView:

FixedExtentScrollPhysics with ListWhellScrollView:

5. PageScrollPhysics:

This ScrollPhysics is mainly used with PageView and its variant. This makes the scrolling of pages smoother compared to any other ScrollPhysics. This can also be used with other scrollable widgets but you will notice it made your scroll smoother than required!

Hope you enjoyed this article!

If you loved it, you can Buy Me A Coffee!

Don’t forget to connect with me on:

Don’t stop, until you are breathing!💙
- Abhishek Doshi

--

--

Abhishek Doshi
Abhishek Doshi

Written by Abhishek Doshi

Google Developer Expert — Dart, Flutter & Firebase 💙💛

Responses (1)