Skip to main content

Mouse Scrolling

using scrollBehavior: .. in MaterialApp or CupertinoApp

// ...
return MaterialApp(
scrollBehavior: const MaterialScrollBehavior().copyWith(
dragDevices: {
PointerDeviceKind.mouse,
PointerDeviceKind.touch,
PointerDeviceKind.stylus,
PointerDeviceKind.trackpad,
PointerDeviceKind.unknown,
},
),
// .....
// ....

Another way using (super.dragDevices)

note

The advantage is, that you don't need to worry about other PointerDeviceKind, because the super getter as other ones too!

main.dart
class MyCustomScrollBehavior extends CupertinoScrollBehavior { /// if its `MaterialApp` then use `MaterialScrollBehavior`
const MyCustomScrollBehavior();


Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.mouse,
}..addAll(super.dragDevices);
}


class MyApp extends StatelessWidget {
/* ...
....
....
*/
return MaterialApp(
scrollBehavior: const MyCustomScrollBehavior(),
// .....
// ....

References