|
|
|
|
@ -78,21 +78,11 @@ class _MultipleItemDropDownMenuState<T extends Base, X extends LoadingListNotifi
|
|
|
|
|
..clear()
|
|
|
|
|
..addAll(results.cast<T>());
|
|
|
|
|
|
|
|
|
|
// Call onSelect if items changed
|
|
|
|
|
if (widget.onSelect != null) {
|
|
|
|
|
widget.onSelect!(_selectedItem);
|
|
|
|
|
}
|
|
|
|
|
// Don't call onSelect in initState - parent already has the initialValue
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (widget.initialValue != null) {
|
|
|
|
|
// final result = (X == NullableLoadingProvider ? widget.staticData : provider?.items)?.where((element) => element.identifier == widget.initialValue?.identifier);
|
|
|
|
|
// if (result?.isNotEmpty ?? false) _selectedItem.add(result!.first as T);
|
|
|
|
|
// if (widget.onSelect != null && (widget.initialValue?.identifier ?? "") != (_selectedItem?.identifier ?? "")) {
|
|
|
|
|
// widget.onSelect!(_selectedItem); // Non-null assertion after null check
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -103,43 +93,47 @@ class _MultipleItemDropDownMenuState<T extends Base, X extends LoadingListNotifi
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void didUpdateWidget(covariant MultipleItemDropDownMenu<T, X> oldWidget) {
|
|
|
|
|
if (widget.initialValue.isNotEmpty) {
|
|
|
|
|
// Get the source list
|
|
|
|
|
final sourceList = (X == NullableLoadingProvider ? widget.staticData : provider?.items);
|
|
|
|
|
if (sourceList != null && sourceList.isNotEmpty) {
|
|
|
|
|
// Collect matches based on identifier
|
|
|
|
|
|
|
|
|
|
final results = sourceList.where((element) => widget.initialValue!.any((init) => init.name == element.name)).toList();
|
|
|
|
|
if (results.isNotEmpty) {
|
|
|
|
|
_selectedItem
|
|
|
|
|
..clear()
|
|
|
|
|
..addAll(results.cast<T>());
|
|
|
|
|
|
|
|
|
|
// Call onSelect if items changed
|
|
|
|
|
if (widget.onSelect != null) {
|
|
|
|
|
widget.onSelect!(_selectedItem);
|
|
|
|
|
// Only update if initialValue actually changed from the old widget
|
|
|
|
|
if (_hasInitialValueChanged(oldWidget)) {
|
|
|
|
|
if (widget.initialValue.isNotEmpty) {
|
|
|
|
|
// Get the source list
|
|
|
|
|
final sourceList = (X == NullableLoadingProvider ? widget.staticData : provider?.items);
|
|
|
|
|
if (sourceList != null && sourceList.isNotEmpty) {
|
|
|
|
|
// Collect matches based on identifier
|
|
|
|
|
final results = sourceList.where((element) => widget.initialValue!.any((init) => init.name == element.name)).toList();
|
|
|
|
|
if (results.isNotEmpty) {
|
|
|
|
|
_selectedItem
|
|
|
|
|
..clear()
|
|
|
|
|
..addAll(results.cast<T>());
|
|
|
|
|
|
|
|
|
|
// Don't call onSelect here - it will create infinite loop
|
|
|
|
|
// The parent already has the correct value
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// initialValue is empty, clear selection
|
|
|
|
|
_selectedItem.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (widget.initialValue != null) {
|
|
|
|
|
// final result = (X == NullableLoadingProvider ? widget.staticData : provider?.items)?.where((element) => element.identifier == widget.initialValue?.identifier);
|
|
|
|
|
//
|
|
|
|
|
// if (result?.isNotEmpty ?? false) {
|
|
|
|
|
// _selectedItem.add(result!.first as T);
|
|
|
|
|
// } else {
|
|
|
|
|
// _selectedItem = [];
|
|
|
|
|
// }
|
|
|
|
|
// // if (widget.onSelect != null && (widget.initialValue?.identifier ?? "") != (_selectedItem?.identifier ?? "")) {
|
|
|
|
|
// // widget.onSelect!(_selectedItem); // Non-null assertion after null check
|
|
|
|
|
// // }
|
|
|
|
|
// } else {
|
|
|
|
|
// _selectedItem = [];
|
|
|
|
|
// }
|
|
|
|
|
super.didUpdateWidget(oldWidget);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool _hasInitialValueChanged(MultipleItemDropDownMenu<T, X> oldWidget) {
|
|
|
|
|
if (oldWidget.initialValue.length != widget.initialValue.length) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (widget.initialValue.isEmpty && oldWidget.initialValue.isEmpty) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Compare items by name
|
|
|
|
|
for (int i = 0; i < widget.initialValue.length; i++) {
|
|
|
|
|
if (!oldWidget.initialValue.any((old) => old.name == widget.initialValue[i].name)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final isEmpty = (X == NullableLoadingProvider ? widget.staticData : provider?.items)?.isEmpty ?? true;
|
|
|
|
|
|