@@ -2,6 +2,8 @@ import 'package:flutter/gestures.dart';
22import 'package:flutter/widgets.dart' ;
33
44class BouncingScrollBehavior extends ScrollBehavior {
5+ const BouncingScrollBehavior ();
6+
57 // Disable overscroll glow.
68 @override
79 Widget buildOverscrollIndicator (
@@ -35,20 +37,23 @@ class BouncingScrollWrapper extends StatelessWidget {
3537
3638 @override
3739 Widget build (BuildContext context) {
40+ ScrollBehavior scrollBehavior = const BouncingScrollBehavior ();
41+ if (dragWithMouse) {
42+ // If mouse dragging is desired, add it to the drag devices.
43+ scrollBehavior = scrollBehavior.copyWith (
44+ dragDevices: scrollBehavior.dragDevices..add (PointerDeviceKind .mouse),
45+ );
46+ }
3847 return ScrollConfiguration (
39- behavior: BouncingScrollBehavior ().copyWith (
40- dragDevices: dragWithMouse
41- ? {
42- PointerDeviceKind .touch,
43- PointerDeviceKind .mouse,
44- }
45- : null ),
48+ behavior: scrollBehavior,
4649 child: child,
4750 );
4851 }
4952}
5053
5154class ClampingScrollBehavior extends ScrollBehavior {
55+ const ClampingScrollBehavior ();
56+
5257 // Disable overscroll glow.
5358 @override
5459 Widget buildOverscrollIndicator (
@@ -77,14 +82,15 @@ class ClampingScrollWrapper extends StatelessWidget {
7782
7883 @override
7984 Widget build (BuildContext context) {
85+ ScrollBehavior scrollBehavior = const ClampingScrollBehavior ();
86+ if (dragWithMouse) {
87+ // If mouse dragging is desired, add it to the drag devices.
88+ scrollBehavior = scrollBehavior.copyWith (
89+ dragDevices: scrollBehavior.dragDevices..add (PointerDeviceKind .mouse),
90+ );
91+ }
8092 return ScrollConfiguration (
81- behavior: ClampingScrollBehavior ().copyWith (
82- dragDevices: dragWithMouse
83- ? {
84- PointerDeviceKind .touch,
85- PointerDeviceKind .mouse,
86- }
87- : null ),
93+ behavior: scrollBehavior,
8894 child: child,
8995 );
9096 }
0 commit comments