select<k> method
Null safety
- k value
select one item in group ( singeSelection/multiple selection)
value
: (dynamic) value of item that should selected
Implementation
@override
void select<k>(k value) {
assert(!(value is List),
"you should use `selectItems` instead of select is only for one value");
assert(_widgetState.values.contains(value),
"you cannot select item that doesn't exist");
switch (isMultipleSelection) {
case true:
_widgetState.selectValues(List.filled(1, value).cast<k>().toList());
break;
case false:
final index = _widgetState.values.indexOf(value);
_widgetState.notifierItems[index].value =
_widgetState.notifierItems[index].value.copy(
checked: true,
);
if (_widgetState.selectedValue.value != null) {
final indexOld =
_widgetState.values.indexOf(_widgetState.selectedValue.value);
if (indexOld != -1) {
_widgetState.notifierItems[indexOld].value =
_widgetState.notifierItems[indexOld].value.copy(
checked: false,
);
}
}
_widgetState.selectedValue.value = value;
break;
}
}