setCheckChange method
data:需要比较的对象 compare:比较器 说明:当是同一数据源则可以不传比较器,直接比较对象地址。 当非同一数据源时(网络接口等),必须传入比较器,根据数据源字段信息比较(eg:id 等)
Implementation
Future<bool> setCheckChange({required T data, Compare? compare}) {
final initValue = _checkedData;
if (widget.maxChecked <= initValue.length) {
return Future.value(false);
}
bool isChecked = false;
///如果外部不传入比较器 则默认比较对象是否一致
if (compare == null) {
isChecked = initValue.contains(data);
} else {
isChecked = compare(initValue);
}
///多选
if (widget.enableMultipleChoice) {
if (isChecked) {
initValue.remove(data);
} else {
initValue.add(data);
}
}
///单选
if (!widget.enableMultipleChoice) {
if (isChecked) {
initValue.remove(data);
} else {
initValue.clear();
initValue.add(data);
}
}
if (widget.buildCheckedBarStyle != null) {
final offset = _checkedData.length * widget.checkedItemWidth!+
widget.checkedItemWidth! * 10 +
_editingController.text.length;
if (_scrollController.hasClients) {
if (_checkedData.length > oldSize) {
_scrollController.animateTo(offset,
duration: widget.duration, curve: widget.curve);
} else {
_scrollController.jumpTo(offset);
}
oldSize = _checkedData.length;
}
}
if (widget.enableClickClear) {
_editingController.text = "";
}
///刷新搜索列表
notyOverlayDataChange();
///刷新输入框组件
// notyListUiChange();
notyCheckedBoxChange();
if (widget.autoClose) {
_removePop();
}
return Future.value(true);
}