Skip to content

Commit

Permalink
Adds new configurable option to shrink wrap list items using S2Choice…
Browse files Browse the repository at this point in the history
…Config.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.
  • Loading branch information
absar committed Sep 22, 2022
1 parent bd65474 commit 34290ec
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/src/choices_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class S2ChoicesList<T> 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),
Expand All @@ -82,7 +82,7 @@ class S2ChoicesList<T> 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),
Expand All @@ -94,7 +94,7 @@ class S2ChoicesList<T> 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),
Expand Down
8 changes: 8 additions & 0 deletions lib/src/model/choice_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
Expand Down Expand Up @@ -166,6 +171,7 @@ class S2ChoiceConfig with Diagnosticable {
ScrollPhysics? physics,
int? pageLimit,
Duration? delay,
bool? shrinkWrap,
}) {
return S2ChoiceConfig(
type: type ?? this.type,
Expand All @@ -187,6 +193,7 @@ class S2ChoiceConfig with Diagnosticable {
physics: physics ?? this.physics,
pageLimit: pageLimit ?? this.pageLimit,
delay: delay ?? this.delay,
shrinkWrap: shrinkWrap ?? this.shrinkWrap,
);
}

Expand Down Expand Up @@ -216,6 +223,7 @@ class S2ChoiceConfig with Diagnosticable {
physics: other.physics,
pageLimit: other.pageLimit,
delay: other.delay,
shrinkWrap: other.shrinkWrap,
);
}
}
10 changes: 10 additions & 0 deletions lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ class SmartSelect<T> 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],
Expand Down Expand Up @@ -419,6 +422,7 @@ class SmartSelect<T> extends StatefulWidget {
double? choiceGridSpacing,
int? choicePageLimit,
Duration? choiceDelay,
bool? choiceShrinkWrap,
S2GroupConfig? groupConfig,
bool? groupEnabled,
bool? groupSelector,
Expand Down Expand Up @@ -494,6 +498,7 @@ class SmartSelect<T> extends StatefulWidget {
activeStyle: choiceActiveStyle,
pageLimit: choicePageLimit,
delay: choiceDelay,
shrinkWrap: choiceShrinkWrap,
),
groupConfig: defaultGroupConfig.merge(groupConfig).copyWith(
enabled: groupEnabled ?? choiceGrouped,
Expand Down Expand Up @@ -647,6 +652,9 @@ class SmartSelect<T> 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],
Expand Down Expand Up @@ -742,6 +750,7 @@ class SmartSelect<T> extends StatefulWidget {
double? choiceGridSpacing,
int? choicePageLimit,
Duration? choiceDelay,
bool? choiceShrinkWrap,
S2GroupConfig? groupConfig,
bool? groupEnabled,
bool? groupSelector,
Expand Down Expand Up @@ -817,6 +826,7 @@ class SmartSelect<T> extends StatefulWidget {
activeStyle: choiceActiveStyle,
pageLimit: choicePageLimit,
delay: choiceDelay,
shrinkWrap: choiceShrinkWrap,
),
groupConfig: defaultGroupConfig.merge(groupConfig).copyWith(
enabled: groupEnabled ?? choiceGrouped,
Expand Down

0 comments on commit 34290ec

Please sign in to comment.