bug 1955 fixed.

main_production_RSG
Sikander Saleem 1 month ago
parent a5796ad2db
commit 471ce223e1

@ -54,12 +54,30 @@ class _DeviceFilterScreenState extends State<DeviceFilterScreen> {
// Initialize selected departments from filter // Initialize selected departments from filter
if (filter.departments != null && filter.departments!.isNotEmpty) { if (filter.departments != null && filter.departments!.isNotEmpty) {
_selectedDepartments = departmentProvider.items.where((dept) => filter.departments!.contains(dept.name)).toList(); _selectedDepartments = [];
for (var deptName in filter.departments!) {
final match = departmentProvider.items.firstWhere(
(dept) => dept.name == deptName,
orElse: () => Lookup(),
);
if (match.id != null) {
_selectedDepartments.add(match);
}
}
} }
// Initialize selected sites from filter // Initialize selected sites from filter
if (filter.sites != null && filter.sites!.isNotEmpty) { if (filter.sites != null && filter.sites!.isNotEmpty) {
_selectedSites = siteProvider.items.where((site) => filter.sites!.contains(site.name)).toList(); _selectedSites = [];
for (var siteName in filter.sites!) {
final match = siteProvider.items.firstWhere(
(site) => site.name == siteName,
orElse: () => Site(),
);
if (match.id != null) {
_selectedSites.add(match);
}
}
} }
loading = false; loading = false;
@ -110,8 +128,9 @@ class _DeviceFilterScreenState extends State<DeviceFilterScreen> {
MultipleItemDropDownMenu<Lookup, DepartmentProvider>( MultipleItemDropDownMenu<Lookup, DepartmentProvider>(
context: context, context: context,
title: context.translation.byDepartment, title: context.translation.byDepartment,
initialValue: _selectedDepartments,
showAsBottomSheet: true, showAsBottomSheet: true,
backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white, // backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white,
// backgroundColor: AppColor.fieldBgColor(context), // backgroundColor: AppColor.fieldBgColor(context),
showShadow: true, showShadow: true,
height: 56.toScreenHeight, height: 56.toScreenHeight,
@ -128,6 +147,7 @@ class _DeviceFilterScreenState extends State<DeviceFilterScreen> {
MultipleItemDropDownMenu<Site, SiteProvider>( MultipleItemDropDownMenu<Site, SiteProvider>(
context: context, context: context,
title: context.translation.bySite, title: context.translation.bySite,
initialValue: _selectedSites,
showAsBottomSheet: true, showAsBottomSheet: true,
// backgroundColor: AppColor.fieldBgColor(context), // backgroundColor: AppColor.fieldBgColor(context),
backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white, backgroundColor: context.isDark ? AppColor.neutral60 : Colors.white,

@ -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/int_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_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/new_views/common_widgets/app_loading_manager.dart';
import 'package:test_sa/providers/loading_list_notifier.dart'; import 'package:test_sa/providers/loading_list_notifier.dart';
import 'package:test_sa/views/widgets/bottom_sheets/selection_bottom_sheet.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); final sourceList = (X == NullableLoadingProvider ? widget.staticData : provider?.items);
if (sourceList != null && sourceList.isNotEmpty) { if (sourceList != null && sourceList.isNotEmpty) {
// Collect matches based on identifier // Collect matches based on identifier or name
final results = sourceList.where((element) => widget.initialValue!.any((init) => init.name == element.name)).toList(); // 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) { if (results.isNotEmpty) {
_selectedItem _selectedItem
@ -100,8 +116,24 @@ class _MultipleItemDropDownMenuState<T extends Base, X extends LoadingListNotifi
// Get the source list // Get the source list
final sourceList = (X == NullableLoadingProvider ? widget.staticData : provider?.items); final sourceList = (X == NullableLoadingProvider ? widget.staticData : provider?.items);
if (sourceList != null && sourceList.isNotEmpty) { if (sourceList != null && sourceList.isNotEmpty) {
// Collect matches based on identifier // Collect matches based on identifier or name
final results = sourceList.where((element) => widget.initialValue!.any((init) => init.name == element.name)).toList(); // 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) { if (results.isNotEmpty) {
_selectedItem _selectedItem
..clear() ..clear()
@ -126,9 +158,24 @@ class _MultipleItemDropDownMenuState<T extends Base, X extends LoadingListNotifi
if (widget.initialValue.isEmpty && oldWidget.initialValue.isEmpty) { if (widget.initialValue.isEmpty && oldWidget.initialValue.isEmpty) {
return false; return false;
} }
// Compare items by name // Compare items by identifier/id/value
for (int i = 0; i < widget.initialValue.length; i++) { 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; return true;
} }
} }

@ -29,7 +29,16 @@ class _AssetStatusButtonsState extends State<AssetStatusButtons> {
WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) { WidgetsFlutterBinding.ensureInitialized().addPostFrameCallback((timeStamp) {
final provider = Provider.of<CommissioningStatusProvider>(context, listen: false); final provider = Provider.of<CommissioningStatusProvider>(context, listen: false);
provider.getData().then((value) { provider.getData().then((value) {
if (widget.initialValue != null) _selectedIndex = provider.items.indexOf(widget.initialValue!); if (widget.initialValue != null) {
// Find matching item by id or value, not by object identity
_selectedIndex = provider.items.indexWhere((item) =>
(item.id != null && item.id == widget.initialValue!.id) ||
(item.value != null && item.value == widget.initialValue!.value)
);
if (_selectedIndex == -1) _selectedIndex = 0;
// Adjust for "All Assets" option at index 0
_selectedIndex += 1;
}
setState(() {}); setState(() {});
}); });
}); });
@ -40,7 +49,17 @@ class _AssetStatusButtonsState extends State<AssetStatusButtons> {
if (widget.initialValue != oldWidget.initialValue) { if (widget.initialValue != oldWidget.initialValue) {
final provider = Provider.of<CommissioningStatusProvider>(context, listen: false); final provider = Provider.of<CommissioningStatusProvider>(context, listen: false);
if (widget.initialValue != null) { if (widget.initialValue != null) {
_selectedIndex = provider.items.indexOf(widget.initialValue!); // Find matching item by id or value, not by object identity
_selectedIndex = provider.items.indexWhere((item) =>
(item.id != null && item.id == widget.initialValue!.id) ||
(item.value != null && item.value == widget.initialValue!.value)
);
if (_selectedIndex == -1) {
_selectedIndex = 0;
} else {
// Adjust for "All Assets" option at index 0
_selectedIndex += 1;
}
} else { } else {
_selectedIndex = 0; _selectedIndex = 0;
} }

Loading…
Cancel
Save