|
|
|
|
@ -5,6 +5,7 @@ import 'package:test_sa/extensions/context_extension.dart';
|
|
|
|
|
import 'package:test_sa/extensions/int_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/text_extensions.dart';
|
|
|
|
|
import 'package:test_sa/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:test_sa/models/lookup.dart';
|
|
|
|
|
import 'package:test_sa/new_views/common_widgets/app_loading_manager.dart';
|
|
|
|
|
import 'package:test_sa/providers/loading_list_notifier.dart';
|
|
|
|
|
import 'package:test_sa/views/widgets/bottom_sheets/selection_bottom_sheet.dart';
|
|
|
|
|
@ -71,8 +72,23 @@ class _MultipleItemDropDownMenuState<T extends Base, X extends LoadingListNotifi
|
|
|
|
|
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();
|
|
|
|
|
// Collect matches based on identifier or name
|
|
|
|
|
// For Lookup: compare by id/value; For others: compare by identifier/name
|
|
|
|
|
final results = sourceList.where((element) {
|
|
|
|
|
return widget.initialValue!.any((init) {
|
|
|
|
|
// Try Lookup-specific comparison first (id/value)
|
|
|
|
|
if (element is Lookup && init is Lookup) {
|
|
|
|
|
return (element.id != null && element.id == init.id) ||
|
|
|
|
|
(element.value != null && element.value == init.value);
|
|
|
|
|
}
|
|
|
|
|
// Fallback to identifier comparison
|
|
|
|
|
if (element.identifier != null && init.identifier != null) {
|
|
|
|
|
return element.identifier == init.identifier;
|
|
|
|
|
}
|
|
|
|
|
// Last resort: name comparison
|
|
|
|
|
return element.name != null && element.name == init.name;
|
|
|
|
|
});
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
|
|
if (results.isNotEmpty) {
|
|
|
|
|
_selectedItem
|
|
|
|
|
@ -100,8 +116,24 @@ class _MultipleItemDropDownMenuState<T extends Base, X extends LoadingListNotifi
|
|
|
|
|
// 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();
|
|
|
|
|
// Collect matches based on identifier or name
|
|
|
|
|
// For Lookup: compare by id/value; For others: compare by identifier/name
|
|
|
|
|
final results = sourceList.where((element) {
|
|
|
|
|
return widget.initialValue!.any((init) {
|
|
|
|
|
// Try Lookup-specific comparison first (id/value)
|
|
|
|
|
if (element is Lookup && init is Lookup) {
|
|
|
|
|
return (element.id != null && element.id == init.id) ||
|
|
|
|
|
(element.value != null && element.value == init.value);
|
|
|
|
|
}
|
|
|
|
|
// Fallback to identifier comparison
|
|
|
|
|
if (element.identifier != null && init.identifier != null) {
|
|
|
|
|
return element.identifier == init.identifier;
|
|
|
|
|
}
|
|
|
|
|
// Last resort: name comparison
|
|
|
|
|
return element.name != null && element.name == init.name;
|
|
|
|
|
});
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
|
|
if (results.isNotEmpty) {
|
|
|
|
|
_selectedItem
|
|
|
|
|
..clear()
|
|
|
|
|
@ -126,9 +158,24 @@ class _MultipleItemDropDownMenuState<T extends Base, X extends LoadingListNotifi
|
|
|
|
|
if (widget.initialValue.isEmpty && oldWidget.initialValue.isEmpty) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Compare items by name
|
|
|
|
|
// Compare items by identifier/id/value
|
|
|
|
|
for (int i = 0; i < widget.initialValue.length; i++) {
|
|
|
|
|
if (!oldWidget.initialValue.any((old) => old.name == widget.initialValue[i].name)) {
|
|
|
|
|
final current = widget.initialValue[i];
|
|
|
|
|
final hasMatch = oldWidget.initialValue.any((old) {
|
|
|
|
|
// Try Lookup-specific comparison first (id/value)
|
|
|
|
|
if (old is Lookup && current is Lookup) {
|
|
|
|
|
return (old.id != null && old.id == current.id) ||
|
|
|
|
|
(old.value != null && old.value == current.value);
|
|
|
|
|
}
|
|
|
|
|
// Fallback to identifier comparison
|
|
|
|
|
if (old.identifier != null && current.identifier != null) {
|
|
|
|
|
return old.identifier == current.identifier;
|
|
|
|
|
}
|
|
|
|
|
// Last resort: name comparison
|
|
|
|
|
return old.name != null && old.name == current.name;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!hasMatch) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|