[FIX] Chip selector configurations is constant
This commit is contained in:
@@ -109,7 +109,6 @@ class _AstromicChipSelectorState<T> extends State<AstromicChipSelector<T>> {
|
||||
//s1 --Controllers
|
||||
//
|
||||
//s1 --State
|
||||
late AstromicChipSelectorConfiguration _configuration;
|
||||
late List<T> selectedItems;
|
||||
//s1 --State
|
||||
//
|
||||
@@ -127,7 +126,6 @@ class _AstromicChipSelectorState<T> extends State<AstromicChipSelector<T>> {
|
||||
//s1 --Controllers & Listeners
|
||||
//
|
||||
//s1 --State
|
||||
_configuration = widget.configuration ?? const AstromicChipSelectorConfiguration();
|
||||
selectedItems = widget.initialSelectedValues ?? [];
|
||||
//s1 --State
|
||||
//
|
||||
@@ -178,23 +176,26 @@ class _AstromicChipSelectorState<T> extends State<AstromicChipSelector<T>> {
|
||||
//
|
||||
//s1 -Widgets
|
||||
List<Widget> baseChildren = widget.items.map((currentItem) {
|
||||
//
|
||||
AstromicChipSelectorConfiguration configuration = widget.configuration ?? const AstromicChipSelectorConfiguration();
|
||||
//
|
||||
int currentIndex = widget.items.indexOf(currentItem);
|
||||
T? previousItem = currentIndex == 0 ? null : widget.items[widget.items.indexOf(currentItem) - 1].$1;
|
||||
T? nextItem = currentIndex == widget.items.length - 1 ? null : widget.items[widget.items.indexOf(currentItem) + 1].$1;
|
||||
bool isConsequent = _configuration.isConsequent;
|
||||
bool isConsequent = configuration.isConsequent;
|
||||
//
|
||||
bool isEnabled = currentItem.$2;
|
||||
bool isSelected = selectedItems.contains(currentItem.$1);
|
||||
bool isPreviousItemSelected = selectedItems.contains(previousItem);
|
||||
bool isNextItemSelected = selectedItems.contains(nextItem);
|
||||
// ---
|
||||
bool canBeSelected = (isConsequent && isEnabled && !isSelected && selectedItems.length < (_configuration.maxSelectedItems) && (isPreviousItemSelected || currentIndex == 0)) ||
|
||||
(!isConsequent && isEnabled && !isSelected && selectedItems.length < (_configuration.maxSelectedItems));
|
||||
bool canBeSelected = (isConsequent && isEnabled && !isSelected && selectedItems.length < (configuration.maxSelectedItems) && (isPreviousItemSelected || currentIndex == 0)) ||
|
||||
(!isConsequent && isEnabled && !isSelected && selectedItems.length < (configuration.maxSelectedItems));
|
||||
bool canbeUnselected = (isConsequent && isEnabled && isSelected && (!isNextItemSelected || currentIndex == widget.items.length - 1)) || (!isConsequent && isEnabled && isSelected);
|
||||
// ---
|
||||
bool tapable = (isSelected && canbeUnselected) || (!isSelected && canBeSelected);
|
||||
// ---
|
||||
bool canShowClear = _configuration.withClearButton && canbeUnselected;
|
||||
bool canShowClear = configuration.withClearButton && canbeUnselected;
|
||||
// ---
|
||||
//
|
||||
return widget.itemBuilder(
|
||||
@@ -207,17 +208,16 @@ class _AstromicChipSelectorState<T> extends State<AstromicChipSelector<T>> {
|
||||
}).toList();
|
||||
//s1 -Widgets
|
||||
//!SECTION
|
||||
|
||||
//SECTION - Build Return
|
||||
return widget.isCustom && widget.groupBuilder != null
|
||||
? widget.groupBuilder!(baseChildren)
|
||||
: _configuration.isWrap
|
||||
: (widget.configuration?.isWrap ?? true)
|
||||
? Wrap(
|
||||
spacing: widget.itemSpacing!,
|
||||
runSpacing: widget.runSpacing!,
|
||||
//
|
||||
alignment: _configuration.wrapMainAllignment,
|
||||
crossAxisAlignment: _configuration.wrapCrossAllignment,
|
||||
alignment: (widget.configuration?.wrapMainAllignment ?? WrapAlignment.start),
|
||||
crossAxisAlignment: (widget.configuration?.wrapCrossAllignment ?? WrapCrossAlignment.start),
|
||||
//
|
||||
children: baseChildren,
|
||||
)
|
||||
@@ -227,7 +227,7 @@ class _AstromicChipSelectorState<T> extends State<AstromicChipSelector<T>> {
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.zero,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
mainAxisExtent: _configuration.fixedRowHeight,
|
||||
mainAxisExtent: widget.configuration?.fixedRowHeight,
|
||||
// number of items per row
|
||||
crossAxisCount: widget.configuration?.crossAxisCount ?? 1,
|
||||
// vertical spacing between the items
|
||||
|
||||
Reference in New Issue
Block a user