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