From 77736fa5a7e6b82c0ad3f67685e3729eedb422cf Mon Sep 17 00:00:00 2001 From: Giuseppe Alfredo Dimola <131204423+lazyengi@users.noreply.github.com> Date: Sun, 19 May 2024 02:06:24 +0200 Subject: [PATCH] Added a function that can provide a decision between a snap or not in my case i needed to stop to snap when the keyboard is open --- lib/scroll_snap_list.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/scroll_snap_list.dart b/lib/scroll_snap_list.dart index 9e1d843..b473d54 100644 --- a/lib/scroll_snap_list.dart +++ b/lib/scroll_snap_list.dart @@ -123,6 +123,8 @@ class ScrollSnapList extends StatefulWidget { final EdgeInsetsGeometry? listViewPadding; + final bool Function()? canIScroll; + ScrollSnapList( {this.background, required this.itemBuilder, @@ -154,7 +156,8 @@ class ScrollSnapList extends StatefulWidget { this.clipBehavior = Clip.hardEdge, this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, this.dispatchScrollNotifications = false, - this.listViewPadding}) + this.listViewPadding, + this.canIScroll}) : listController = listController ?? ScrollController(), super(key: key); @@ -383,6 +386,9 @@ class ScrollSnapListState extends State { //only animate if not yet snapped (tolerance 0.01 pixel) if ((scrollInfo.metrics.pixels - offset).abs() > 0.01) { + if (widget.canIScroll != null && !widget.canIScroll!()) { + return false; + } _animateScroll(offset); } } else if (scrollInfo is ScrollUpdateNotification) {