From ecb910f975ecbfdd177471fe4ea5ad7650cdf3b2 Mon Sep 17 00:00:00 2001 From: Jamiu Okanlawon Date: Wed, 6 Mar 2024 16:22:58 +0100 Subject: [PATCH] [scrollable_positioned_list] Keyboard dismiss behavior --- .../lib/src/positioned_list.dart | 7 +++++++ .../scrollable_positioned_list/lib/src/scroll_view.dart | 3 +++ .../lib/src/scrollable_positioned_list.dart | 9 +++++++++ 3 files changed, 19 insertions(+) diff --git a/packages/scrollable_positioned_list/lib/src/positioned_list.dart b/packages/scrollable_positioned_list/lib/src/positioned_list.dart index 5c6929e0..cfc7599e 100644 --- a/packages/scrollable_positioned_list/lib/src/positioned_list.dart +++ b/packages/scrollable_positioned_list/lib/src/positioned_list.dart @@ -44,6 +44,7 @@ class PositionedList extends StatefulWidget { this.addSemanticIndexes = true, this.addRepaintBoundaries = true, this.addAutomaticKeepAlives = true, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, }) : assert(itemCount != null), assert(itemBuilder != null), assert((positionedIndex == 0) || (positionedIndex < itemCount)), @@ -132,6 +133,11 @@ class PositionedList extends StatefulWidget { /// See [SliverChildBuilderDelegate.addAutomaticKeepAlives]. final bool addAutomaticKeepAlives; + /// Defines how this [ScrollView] will dismiss the keyboard automatically. + /// + /// See [ScrollView.keyboardDismissBehavior]. + final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior; + @override State createState() => _PositionedListState(); } @@ -177,6 +183,7 @@ class _PositionedListState extends State { physics: widget.physics, shrinkWrap: widget.shrinkWrap, semanticChildCount: widget.semanticChildCount ?? widget.itemCount, + keyboardDismissBehavior: widget.keyboardDismissBehavior, slivers: [ if (widget.positionedIndex > 0) SliverPadding( diff --git a/packages/scrollable_positioned_list/lib/src/scroll_view.dart b/packages/scrollable_positioned_list/lib/src/scroll_view.dart index 31acda40..e64c7d66 100644 --- a/packages/scrollable_positioned_list/lib/src/scroll_view.dart +++ b/packages/scrollable_positioned_list/lib/src/scroll_view.dart @@ -28,6 +28,8 @@ class UnboundedCustomScrollView extends CustomScrollView { List slivers = const [], int? semanticChildCount, DragStartBehavior dragStartBehavior = DragStartBehavior.start, + ScrollViewKeyboardDismissBehavior keyboardDismissBehavior = + ScrollViewKeyboardDismissBehavior.manual, }) : _shrinkWrap = shrinkWrap, _anchor = anchor, super( @@ -43,6 +45,7 @@ class UnboundedCustomScrollView extends CustomScrollView { semanticChildCount: semanticChildCount, dragStartBehavior: dragStartBehavior, slivers: slivers, + keyboardDismissBehavior: keyboardDismissBehavior, ); // [CustomScrollView] enforces constraints on [CustomScrollView.anchor], so diff --git a/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart b/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart index 60045e9b..b9363ddd 100644 --- a/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart +++ b/packages/scrollable_positioned_list/lib/src/scrollable_positioned_list.dart @@ -57,6 +57,7 @@ class ScrollablePositionedList extends StatefulWidget { this.addAutomaticKeepAlives = true, this.addRepaintBoundaries = true, this.minCacheExtent, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, }) : assert(itemCount != null), assert(itemBuilder != null), itemPositionsNotifier = itemPositionsListener as ItemPositionsNotifier?, @@ -87,6 +88,7 @@ class ScrollablePositionedList extends StatefulWidget { this.addAutomaticKeepAlives = true, this.addRepaintBoundaries = true, this.minCacheExtent, + this.keyboardDismissBehavior = ScrollViewKeyboardDismissBehavior.manual, }) : assert(itemCount != null), assert(itemBuilder != null), assert(separatorBuilder != null), @@ -186,6 +188,11 @@ class ScrollablePositionedList extends StatefulWidget { /// cache extent. final double? minCacheExtent; + /// Defines how this [ScrollView] will dismiss the keyboard automatically. + /// + /// See [ScrollView.keyboardDismissBehavior]. + final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior; + @override State createState() => _ScrollablePositionedListState(); } @@ -437,6 +444,7 @@ class _ScrollablePositionedListState extends State padding: widget.padding, addAutomaticKeepAlives: widget.addAutomaticKeepAlives, addRepaintBoundaries: widget.addRepaintBoundaries, + keyboardDismissBehavior: widget.keyboardDismissBehavior, ), ), ), @@ -467,6 +475,7 @@ class _ScrollablePositionedListState extends State padding: widget.padding, addAutomaticKeepAlives: widget.addAutomaticKeepAlives, addRepaintBoundaries: widget.addRepaintBoundaries, + keyboardDismissBehavior: widget.keyboardDismissBehavior, ), ), ),