Bug fixes

This commit is contained in:
Abdullah Alassaf
2024-10-09 21:29:20 +03:00
11 changed files with 245 additions and 297 deletions

View File

@ -14,10 +14,9 @@ class DeviceManagementBloc extends Bloc<DeviceManagementEvent, DeviceManagementS
int _lowBatteryCount = 0;
List<AllDevicesModel> _selectedDevices = [];
List<AllDevicesModel> _filteredDevices = [];
String productName = '';
String currentProductName = '';
String? currentCommunity;
String? currentUnitName;
String? currentProductName;
DeviceManagementBloc() : super(DeviceManagementInitial()) {
on<FetchDevices>(_onFetchDevices);
@ -77,14 +76,14 @@ class DeviceManagementBloc extends Bloc<DeviceManagementEvent, DeviceManagementS
isControlButtonEnabled: _selectedDevices.isNotEmpty,
));
if (productName.isNotEmpty) {
add(SearchDevices(productName: productName));
if (currentProductName.isNotEmpty) {
add(SearchDevices(productName: currentProductName));
}
}
}
Future<void> _onResetFilters(ResetFilters event, Emitter<DeviceManagementState> emit) async {
productName = '';
currentProductName = '';
_selectedDevices.clear();
_filteredDevices = List.from(_devices);
_selectedIndex = 0;
@ -238,20 +237,10 @@ class DeviceManagementBloc extends Bloc<DeviceManagementEvent, DeviceManagementS
}
void _onSearchDevices(SearchDevices event, Emitter<DeviceManagementState> emit) {
if (event.productName == currentProductName &&
event.community == currentCommunity &&
event.unitName == currentUnitName) {
return;
}
currentProductName = event.productName;
currentCommunity = event.community;
currentUnitName = event.unitName;
if ((event.community == null || event.community!.isEmpty) &&
(event.unitName == null || event.unitName!.isEmpty) &&
(event.productName == null || event.productName!.isEmpty)) {
productName = '';
currentProductName = '';
if (state is DeviceManagementFiltered) {
add(FilterDevices(_getFilterFromIndex(_selectedIndex)));
} else {
@ -259,7 +248,17 @@ class DeviceManagementBloc extends Bloc<DeviceManagementEvent, DeviceManagementS
}
}
productName = event.productName ?? '';
if (event.productName == currentProductName &&
event.community == currentCommunity &&
event.unitName == currentUnitName &&
event.searchField) {
return;
}
currentProductName = event.productName ?? '';
currentCommunity = event.community;
currentUnitName = event.unitName;
List<AllDevicesModel> devicesToSearch = _filteredDevices;
if (devicesToSearch.isNotEmpty) {

View File

@ -31,11 +31,13 @@ class SearchDevices extends DeviceManagementEvent {
final String? community;
final String? unitName;
final String? productName;
final bool searchField;
const SearchDevices({
this.community,
this.unitName,
this.productName,
this.searchField = false,
});
@override

View File

@ -67,9 +67,10 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters> with HelperRe
controller: controller,
onSubmitted: () {
context.read<DeviceManagementBloc>().add(SearchDevices(
productName: productNameController.text,
unitName: unitNameController.text,
));
productName: productNameController.text,
unitName: unitNameController.text,
community: communityController.text,
searchField: true));
},
);
}
@ -78,10 +79,10 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters> with HelperRe
return SearchResetButtons(
onSearch: () {
context.read<DeviceManagementBloc>().add(SearchDevices(
community: communityController.text,
unitName: unitNameController.text,
productName: productNameController.text,
));
community: communityController.text,
unitName: unitNameController.text,
productName: productNameController.text,
searchField: true));
},
onReset: () {
communityController.clear();