From 34290ec25db7d2c2bf0b1165c05390ea625a5335 Mon Sep 17 00:00:00 2001 From: Absar Date: Thu, 22 Sep 2022 18:23:01 +0200 Subject: [PATCH] Adds new configurable option to shrink wrap list items using S2ChoiceConfig.shrinkWrap or SmartSelect.single/SmartSelect.multiple.choiceShrinkWrap. If choiceShrinkWrap is true choices list will shrink wrap the choices, causing the list to resize based on the number of available choices, by default it will shrink wrap which was the default behaviour before this change. --- lib/src/choices_list.dart | 6 +++--- lib/src/model/choice_config.dart | 8 ++++++++ lib/src/widget.dart | 10 ++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/src/choices_list.dart b/lib/src/choices_list.dart index b13f937..1cc2d4b 100644 --- a/lib/src/choices_list.dart +++ b/lib/src/choices_list.dart @@ -71,7 +71,7 @@ class S2ChoicesList extends StatelessWidget { Widget _listDefault() { return ListView.builder( - shrinkWrap: true, + shrinkWrap: config.shrinkWrap, physics: config.physics, scrollDirection: config.direction, padding: config.padding ?? const EdgeInsets.symmetric(vertical: 10.0), @@ -82,7 +82,7 @@ class S2ChoicesList extends StatelessWidget { Widget _listSeparated() { return ListView.separated( - shrinkWrap: true, + shrinkWrap: config.shrinkWrap, physics: config.physics, scrollDirection: config.direction, padding: config.padding ?? const EdgeInsets.symmetric(vertical: 10.0), @@ -94,7 +94,7 @@ class S2ChoicesList extends StatelessWidget { Widget _listGrid() { return GridView.builder( - shrinkWrap: true, + shrinkWrap: config.shrinkWrap, physics: config.physics, scrollDirection: config.direction, padding: config.padding ?? const EdgeInsets.all(10.0), diff --git a/lib/src/model/choice_config.dart b/lib/src/model/choice_config.dart index 7e57af6..ed4a4f3 100644 --- a/lib/src/model/choice_config.dart +++ b/lib/src/model/choice_config.dart @@ -110,6 +110,10 @@ class S2ChoiceConfig with Diagnosticable { /// Time delay before display the choices final Duration? delay; + /// If true choices list will shrink wrap the choices, causing the list to + /// resize based on the number of available choices. + final bool shrinkWrap; + /// Create choices configuration const S2ChoiceConfig({ this.type, @@ -131,6 +135,7 @@ class S2ChoiceConfig with Diagnosticable { this.physics = const ScrollPhysics(), this.pageLimit, this.delay, + this.shrinkWrap = true, }); /// Whether the [layout] is [S2ChoiceLayout.wrap] or [type] is [S2ChoiceType.chips] @@ -166,6 +171,7 @@ class S2ChoiceConfig with Diagnosticable { ScrollPhysics? physics, int? pageLimit, Duration? delay, + bool? shrinkWrap, }) { return S2ChoiceConfig( type: type ?? this.type, @@ -187,6 +193,7 @@ class S2ChoiceConfig with Diagnosticable { physics: physics ?? this.physics, pageLimit: pageLimit ?? this.pageLimit, delay: delay ?? this.delay, + shrinkWrap: shrinkWrap ?? this.shrinkWrap, ); } @@ -216,6 +223,7 @@ class S2ChoiceConfig with Diagnosticable { physics: other.physics, pageLimit: other.pageLimit, delay: other.delay, + shrinkWrap: other.shrinkWrap, ); } } diff --git a/lib/src/widget.dart b/lib/src/widget.dart index 312c6df..bb3da71 100644 --- a/lib/src/widget.dart +++ b/lib/src/widget.dart @@ -323,6 +323,9 @@ class SmartSelect extends StatefulWidget { /// The [choiceDelay] is shortcut to [choiceConfig.delay], /// time delay before display the choices. /// + /// If [choiceShrinkWrap] is true choices list will shrink wrap the choices, + /// causing the list to resize based on the number of available choices. + /// /// The [groupConfig] is a configuration to customize grouped widget. /// /// The [groupEnabled] is shortcut to [groupConfig.enabled], alternative to [choiceGrouped], @@ -419,6 +422,7 @@ class SmartSelect extends StatefulWidget { double? choiceGridSpacing, int? choicePageLimit, Duration? choiceDelay, + bool? choiceShrinkWrap, S2GroupConfig? groupConfig, bool? groupEnabled, bool? groupSelector, @@ -494,6 +498,7 @@ class SmartSelect extends StatefulWidget { activeStyle: choiceActiveStyle, pageLimit: choicePageLimit, delay: choiceDelay, + shrinkWrap: choiceShrinkWrap, ), groupConfig: defaultGroupConfig.merge(groupConfig).copyWith( enabled: groupEnabled ?? choiceGrouped, @@ -647,6 +652,9 @@ class SmartSelect extends StatefulWidget { /// The [choiceDelay] is shortcut to [choiceConfig.delay], /// time delay before display the choices. /// + /// If [choiceShrinkWrap] is true choices list will shrink wrap the choices, + /// causing the list to resize based on the number of available choices. + /// /// The [groupConfig] is a configuration to customize grouped widget. /// /// The [groupEnabled] is shortcut to [groupConfig.enabled], alternative to [choiceGrouped], @@ -742,6 +750,7 @@ class SmartSelect extends StatefulWidget { double? choiceGridSpacing, int? choicePageLimit, Duration? choiceDelay, + bool? choiceShrinkWrap, S2GroupConfig? groupConfig, bool? groupEnabled, bool? groupSelector, @@ -817,6 +826,7 @@ class SmartSelect extends StatefulWidget { activeStyle: choiceActiveStyle, pageLimit: choicePageLimit, delay: choiceDelay, + shrinkWrap: choiceShrinkWrap, ), groupConfig: defaultGroupConfig.merge(groupConfig).copyWith( enabled: groupEnabled ?? choiceGrouped,