Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

docs.flutter.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.

Learn more

Flutter 3.41 is live! Check out theFlutter 3.41 blog post!

Default multitouch scrolling

ScrollBehaviors will now configure how Scrollables respond to multitouch gestures.

Important

Summary

#

ScrollBehaviors now allow or disallow scrolling speeds to be affected by the number of pointers on the screen.ScrollBehavior.multitouchDragStrategy, by default, prevents multiple pointers interacting wih the scrollable at the same time from affecting the speed of scrolling.

Context

#

Prior to this change, for each pointer dragging aScrollable widget, the scroll speed would increase. This did not match platform expectations when interacting with Flutter applications.

Now, the inheritedScrollBehavior manages how multiple pointers affect scrolling widgets as specified byScrollBehavior.multitouchDragStrategy. This enum,MultitouchDragStrategy, can also be configured for the prior behavior.

Description of change

#

This change fixed the unexpected ability to increase scroll speeds by dragging with more than one finger.

If you have relied on the previous behavior in your application, there are several ways to control and configure this feature.

  • ExtendScrollBehavior,MaterialScrollBehavior, orCupertinoScrollBehavior to modify the default behavior, overridingScrollBehavior.multitouchDragStrategy.

    • With your ownScrollBehavior, you can apply it app-wide by settingMaterialApp.scrollBehavior orCupertinoApp.scrollBehavior.
    • Or, if you wish to only apply it to specific widgets, add aScrollConfiguration above the widget in question with your customScrollBehavior.

Your scrollable widgets then inherit and reflect this behavior.

  • Instead of creating your ownScrollBehavior, another option for changing the default behavior is to copy the existingScrollBehavior, and set differentmultitouchDragStrategy.
    • Create aScrollConfiguration in your widget tree, and provide a modified copy of the existingScrollBehavior in the current context usingcopyWith.

To accommodate the new configurationDragGestureRecognizer was updated to supportMultitouchDragStrategy as well in other dragging contexts.

Migration guide

#

Setting a customScrollBehavior for your application

#

Code before migration:

dart
MaterialApp(// ...);

Code after migration:

dart
classMyCustomScrollBehaviorextendsMaterialScrollBehavior{// Override behavior methods and getters like multitouchDragStrategy@overrideMultitouchDragStrategygetMultitouchDragStrategy(BuildContextcontext)=>MultitouchDragStrategy.sumAllPointers;}// Set ScrollBehavior for an entire application.MaterialApp(scrollBehavior:MyCustomScrollBehavior(),// ...);

Setting a customScrollBehavior for a specific widget

#

Code before migration:

dart
finalScrollControllercontroller=ScrollController();ListView.builder(controller:controller,itemBuilder:(BuildContextcontext,intindex){returnText('Item$index');},);

Code after migration:

dart
classMyCustomScrollBehaviorextendsMaterialScrollBehavior{// Override behavior methods and getters like multitouchDragStrategy@overrideMultitouchDragStrategygetMultitouchDragStrategy(BuildContextcontext)=>MultitouchDragStrategy.sumAllPointers;}// ScrollBehavior can be set for a specific widget.finalScrollControllercontroller=ScrollController();ScrollConfiguration(behavior:MyCustomScrollBehavior(),child:ListView.builder(controller:controller,itemBuilder:(BuildContextcontext,intindex){returnText('Item$index');},),);

Copy and modify existingScrollBehavior

#

Code before migration:

dart
finalScrollControllercontroller=ScrollController();ListView.builder(controller:controller,itemBuilder:(BuildContextcontext,intindex){returnText('Item$index');},);

Code after migration:

dart
// ScrollBehavior can be copied and adjusted.finalScrollControllercontroller=ScrollController();ScrollConfiguration(behavior:ScrollConfiguration.of(context).copyWith(multitouchDragStrategy:MultitouchDragStrategy.sumAllPointers,),child:ListView.builder(controller:controller,itemBuilder:(BuildContextcontext,intindex){returnText('Item$index');},),);

Timeline

#

Landed in version: 3.18.0-4.0.pre
In stable release: 3.19.0

References

#

API documentation:

Relevant issue:

Relevant PRs:

Was this page's content helpful?

Unless stated otherwise, the documentation on this site reflects Flutter 3.38.6. Page last updated on 2025-10-30.View source orreport an issue.


[8]ページ先頭

©2009-2026 Movatter.jp