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();

View File

@ -23,7 +23,7 @@ class _NotificationDialogState extends State<NotificationDialog> {
borderRadius: BorderRadius.circular(20),
),
child: SizedBox(
width: 798,
width: 660,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
@ -70,41 +70,53 @@ class _NotificationDialogState extends State<NotificationDialog> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {
setState(() {
isLowBatteryNotificationEnabled = v;
});
},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isLowBatteryNotificationEnabled,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {
setState(() {
isLowBatteryNotificationEnabled = v;
});
},
icon: '-1',
),
),
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Closing\nReminders',
onChange: (v) {
setState(() {
isClosingRemindersEnabled = v;
});
},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isClosingRemindersEnabled,
code: 'notification',
deviceId: '',
label: 'Closing\nReminders',
onChange: (v) {
setState(() {
isClosingRemindersEnabled = v;
});
},
icon: '-1',
),
),
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Door Alarm',
onChange: (v) {
setState(() {
isDoorAlarmEnabled = v;
});
},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isDoorAlarmEnabled,
code: 'notification',
deviceId: '',
label: 'Door Alarm',
onChange: (v) {
setState(() {
isDoorAlarmEnabled = v;
});
},
icon: '-1',
),
),
],
),

View File

@ -6,12 +6,13 @@ class WaterLeakNotificationDialog extends StatefulWidget {
const WaterLeakNotificationDialog({super.key});
@override
State<WaterLeakNotificationDialog> createState() => _WaterLeakNotificationDialogState();
State<WaterLeakNotificationDialog> createState() => _NotificationDialogState();
}
class _WaterLeakNotificationDialogState extends State<WaterLeakNotificationDialog> {
class _NotificationDialogState extends State<WaterLeakNotificationDialog> {
bool isLowBatteryNotificationEnabled = true;
bool isWaterLeakageNotificationEnabled = true;
bool isClosingRemindersEnabled = true;
bool isWaterLeakage = true;
@override
Widget build(BuildContext context) {
@ -22,7 +23,7 @@ class _WaterLeakNotificationDialogState extends State<WaterLeakNotificationDialo
borderRadius: BorderRadius.circular(20),
),
child: SizedBox(
width: 400,
width: 560,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
@ -69,29 +70,37 @@ class _WaterLeakNotificationDialogState extends State<WaterLeakNotificationDialo
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {
setState(() {
isLowBatteryNotificationEnabled = v;
});
},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isLowBatteryNotificationEnabled,
code: 'notification',
deviceId: '',
label: 'Low Battery',
onChange: (v) {
setState(() {
isLowBatteryNotificationEnabled = v;
});
},
icon: '-1',
),
),
ToggleWidget(
value: true,
code: 'notification',
deviceId: '',
label: 'Water Leakage',
onChange: (v) {
setState(() {
isWaterLeakageNotificationEnabled = v;
});
},
icon: '-1',
SizedBox(
width: 170,
height: 135,
child: ToggleWidget(
value: isWaterLeakage,
code: 'notification',
deviceId: '',
label: 'Water Leakage',
onChange: (v) {
setState(() {
isWaterLeakage = v;
});
},
icon: '-1',
),
),
],
),