horizontal_blocked_scroll_physics 3.0.0

Flutter Android iOS web

A ScrollPhysics class that blocks movement in the horizontal axis.

Horizontal Blocked ScrollPhysics #

Build Status License: MIT Pub

A ScrollPhysics class that blocks movement in the horizontal axis.

How to use it #

The API of this ScrollPhysics is fairly straighforward.

We have two different classes:

  • LeftBlockedScrollPhysics: will block left movements.
  • RightBlockedScrollPhysics: will block right movements.

Blocking movement #

LeftBlockedScrollPhysics();

This will allow the content to be scrolled to the right and will block any scroll to the left.

There's one exception, though. You can see here that the user is swiping to the left (which is blocked) but the screen will be able to move to the left if the movement is not completed. Note that the text will go back to the center.

swiping_left_recovery

Alternatively, if you want to block movement to the right and allow scrolling to the left:

RightBlockedScrollPhysics();

Why are we exposing two classes #

You may have notice that we're exposing two classes instead of only one that uses properties to change the physics behavior. That's because of an optimization in the Scrollable class that doesn't allow to use the same type, even if it's a new instance, in order to change the Scrollable physics behavior.

The physics can be changed dynamically, but new physics will only take effect if the class of the provided object changes. Merely constructing a new instance with a different configuration is insufficient to cause the physics to be reapplied. (This is because the final object used is generated dynamically, which can be relatively expensive, and it would be inefficient to speculatively create this object each frame to see if the physics should be updated.)

That's why Flutter has specific ScrollPhysics like NeverScrollableScrollPhysics and AlwaysScrollableScrollPhysics.

6
likes
110
pub points
78%
popularity

Publisher

alpha.company

A ScrollPhysics class that blocks movement in the horizontal axis.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, pedantic

More

Packages that depend on horizontal_blocked_scroll_physics