From 53393e94326c4fe07267f99ec33562fedac05f17 Mon Sep 17 00:00:00 2001 From: Wizzel1 Date: Sat, 14 Jan 2023 13:38:53 +0100 Subject: [PATCH 1/3] Add scrollSpeed field --- lib/src/scroll_state.dart | 4 ++-- lib/src/source.dart | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/scroll_state.dart b/lib/src/scroll_state.dart index 4da8130..a9d9d8a 100644 --- a/lib/src/scroll_state.dart +++ b/lib/src/scroll_state.dart @@ -14,7 +14,7 @@ class ScrollState with ChangeNotifier { ScrollState(this.mobilePhysics, this.durationMS); - void handleDesktopScroll(PointerSignalEvent event) { + void handleDesktopScroll(PointerSignalEvent event, int scrollSpeed) { // Ensure desktop physics is being used. if (physics == kMobilePhysics) { physics = kDesktopPhysics; @@ -32,7 +32,7 @@ class ScrollState with ChangeNotifier { if (dy > 0) return; } } - futurePosition += event.scrollDelta.dy; + futurePosition += event.scrollDelta.dy * scrollSpeed; controller.animateTo( futurePosition, diff --git a/lib/src/source.dart b/lib/src/source.dart index e49b00e..f98647b 100644 --- a/lib/src/source.dart +++ b/lib/src/source.dart @@ -6,12 +6,14 @@ import 'scroll_state.dart'; class DynMouseScroll extends StatelessWidget { final ScrollPhysics mobilePhysics; final int durationMS; + final int scrollSpeed; final Function(BuildContext, ScrollController, ScrollPhysics) builder; const DynMouseScroll({ super.key, this.mobilePhysics = kMobilePhysics, this.durationMS = 200, + this.scrollSpeed = 1, required this.builder, }); @@ -24,7 +26,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), onPointerDown: scrollState.handleTouchScroll, child: builder(context, controller, physics), ); From 5192c01c2f53f335003471dd3f616e7148593e75 Mon Sep 17 00:00:00 2001 From: Wizzel1 Date: Sat, 14 Jan 2023 13:47:23 +0100 Subject: [PATCH 2/3] Add optional animation curve field --- lib/src/scroll_state.dart | 5 +++-- lib/src/source.dart | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/src/scroll_state.dart b/lib/src/scroll_state.dart index a9d9d8a..d15b880 100644 --- a/lib/src/scroll_state.dart +++ b/lib/src/scroll_state.dart @@ -14,7 +14,8 @@ class ScrollState with ChangeNotifier { ScrollState(this.mobilePhysics, this.durationMS); - void handleDesktopScroll(PointerSignalEvent event, int scrollSpeed) { + void handleDesktopScroll( + PointerSignalEvent event, int scrollSpeed, Curve animationCurve) { // Ensure desktop physics is being used. if (physics == kMobilePhysics) { physics = kDesktopPhysics; @@ -37,7 +38,7 @@ class ScrollState with ChangeNotifier { controller.animateTo( futurePosition, duration: Duration(milliseconds: durationMS), - curve: Curves.linear, + curve: animationCurve, ); } } diff --git a/lib/src/source.dart b/lib/src/source.dart index f98647b..d6440de 100644 --- a/lib/src/source.dart +++ b/lib/src/source.dart @@ -7,6 +7,7 @@ class DynMouseScroll extends StatelessWidget { final ScrollPhysics mobilePhysics; final int durationMS; final int scrollSpeed; + final Curve animationCurve; final Function(BuildContext, ScrollController, ScrollPhysics) builder; const DynMouseScroll({ @@ -14,6 +15,7 @@ class DynMouseScroll extends StatelessWidget { this.mobilePhysics = kMobilePhysics, this.durationMS = 200, this.scrollSpeed = 1, + this.animationCurve = Curves.linear, required this.builder, }); @@ -26,8 +28,8 @@ class DynMouseScroll extends StatelessWidget { final controller = scrollState.controller; final physics = context.select((ScrollState s) => s.physics); return Listener( - onPointerSignal: (signalEvent) => - scrollState.handleDesktopScroll(signalEvent, scrollSpeed), + onPointerSignal: (signalEvent) => scrollState.handleDesktopScroll( + signalEvent, scrollSpeed, animationCurve), onPointerDown: scrollState.handleTouchScroll, child: builder(context, controller, physics), ); From e00e19afd917533d56c217c1b290912da7b7798c Mon Sep 17 00:00:00 2001 From: Wizzel1 Date: Sat, 14 Jan 2023 13:52:11 +0100 Subject: [PATCH 3/3] Bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 112b6c5..2f255e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: