physics property

ScrollPhysics? physics
final

The Axis along which the scroll view's offset increases.

For the direction in which active scrolling may be occurring, see ScrollDirection.

Defaults to Axis.vertical. Whether the scroll view scrolls in the reading direction.

For example, if the reading direction is left-to-right and scrollDirection is Axis.horizontal, then the scroll view scrolls from left to right when reverse is false and from right to left when reverse is true.

Similarly, if scrollDirection is Axis.vertical, then the scroll view scrolls from top to bottom when reverse is false and from bottom to top when reverse is true.

Defaults to false. An object that can be used to control the position to which this scroll view is scrolled.

Must be null if primary is true.

A ScrollController serves several purposes. It can be used to control the initial scroll position (see ScrollController.initialScrollOffset). It can be used to control whether the scroll view should automatically save and restore its scroll position in the PageStorage (see ScrollController.keepScrollOffset). It can be used to read the current scroll position (see ScrollController.offset), or change it (see ScrollController.animateTo). Whether this is the primary scroll view associated with the parent PrimaryScrollController.

When this is true, the scroll view is scrollable even if it does not have sufficient content to actually scroll. Otherwise, by default the user can only scroll the view if it has sufficient content. See physics.

Also when true, the scroll view is used for default ScrollActions. If a ScrollAction is not handled by an otherwise focused part of the application, the ScrollAction will be evaluated using this scroll view, for example, when executing Shortcuts key events like page up and down.

On iOS, this also identifies the scroll view that will scroll to top in response to a tap in the status bar.

Cannot be true while a ScrollController is provided to controller, only one ScrollController can be associated with a ScrollView.

Setting to false will explicitly prevent inheriting any PrimaryScrollController.

Defaults to null. When null, and a controller is not provided, PrimaryScrollController.shouldInherit is used to decide automatic inheritance.

By default, the PrimaryScrollController that is injected by each ModalRoute is configured to automatically be inherited on TargetPlatformVariant.mobile for ScrollViews in the Axis.vertical scroll direction. Adding another to your app will override the PrimaryScrollController above it.

The following video contains more information about scroll controllers, the PrimaryScrollController widget, and their impact on your apps:

Defaults to true when [scrollDirection] is [Axis.vertical] and [scrollController] is null. How the scroll view should respond to user input.

For example, determines how the scroll view continues to animate after the user stops dragging the scroll view.

Defaults to matching platform conventions. Furthermore, if primary is false, then the user cannot scroll if there is insufficient content to scroll, while if primary is true, they can always attempt to scroll.

To force the scroll view to always be scrollable even if there is insufficient content, as if primary was true but without necessarily setting it to true, provide an AlwaysScrollableScrollPhysics physics object, as in:

  physics: const AlwaysScrollableScrollPhysics(),

To force the scroll view to use the default platform conventions and not be scrollable if there is insufficient content, regardless of the value of primary, provide an explicit ScrollPhysics object, as in:

  physics: const ScrollPhysics(),

The physics can be changed dynamically (by providing a new object in a subsequent build), 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.)

Implementation

// final Axis scrollDirection;

/// {@macro flutter.widgets.scroll_view.reverse}
// final bool reverse;

/// {@macro flutter.widgets.scroll_view.controller}
// final ScrollController? scrollController;

/// {@macro flutter.widgets.scroll_view.primary}

/// Defaults to true when [scrollDirection] is [Axis.vertical] and
/// [scrollController] is null.
// final bool? primary;

/// {@macro flutter.widgets.scroll_view.physics}
final ScrollPhysics? physics;