Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/src/scroll_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class ScrollState with ChangeNotifier {

ScrollState(this.mobilePhysics, this.durationMS);

void handleDesktopScroll(PointerSignalEvent event) {
void handleDesktopScroll(
PointerSignalEvent event, int scrollSpeed, Curve animationCurve) {
// Ensure desktop physics is being used.
if (physics == kMobilePhysics) {
physics = kDesktopPhysics;
Expand All @@ -32,12 +33,12 @@ class ScrollState with ChangeNotifier {
if (dy > 0) return;
}
}
futurePosition += event.scrollDelta.dy;
futurePosition += event.scrollDelta.dy * scrollSpeed;

controller.animateTo(
futurePosition,
duration: Duration(milliseconds: durationMS),
curve: Curves.linear,
curve: animationCurve,
);
}
}
Expand Down
7 changes: 6 additions & 1 deletion lib/src/source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import 'scroll_state.dart';
class DynMouseScroll extends StatelessWidget {
final ScrollPhysics mobilePhysics;
final int durationMS;
final int scrollSpeed;
final Curve animationCurve;
final Function(BuildContext, ScrollController, ScrollPhysics) builder;

const DynMouseScroll({
super.key,
this.mobilePhysics = kMobilePhysics,
this.durationMS = 200,
this.scrollSpeed = 1,
this.animationCurve = Curves.linear,
required this.builder,
});

Expand All @@ -24,7 +28,8 @@ class DynMouseScroll extends StatelessWidget {
final controller = scrollState.controller;
final physics = context.select((ScrollState s) => s.physics);
return Listener(
onPointerSignal: scrollState.handleDesktopScroll,
onPointerSignal: (signalEvent) => scrollState.handleDesktopScroll(
signalEvent, scrollSpeed, animationCurve),
onPointerDown: scrollState.handleTouchScroll,
child: builder(context, controller, physics),
);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dyn_mouse_scroll
description: A wrapper for scrollable widgets that enables smooth scrolling with a mouse on all platforms.
version: 1.0.7
version: 1.0.8
repository: https://github.com/Bluebar1/dyn_mouse_scroll

environment:
Expand Down