FLUTTER ECOSYSTEM

koa-health/horizontal_blocked_scroll_physics

一个阻止水平轴移动的 ScrollPhysics 类。

horizontal_blocked_scroll_physics 项目封面
Stars
9
Forks
5
最近推送(UTC)
2022年3月7日
项目状态
未归档
Koa Health GitHub avatar
GITHUB Organization

Koa Health ↗

语言DartSwiftKotlinObjective-C

技术话题

使用的依赖

依赖清单 3 项
  • flutter{"sdk":"flutter"}
  • flutter_lints开发依赖^1.0.4
  • flutter_test开发依赖{"sdk":"flutter"}

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

展开 / 收起项目 README

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.