code refactoring

This commit is contained in:
Mohammad Salameh
2024-03-03 19:07:24 +03:00
parent ad511fe3af
commit d9a3f9e2a0
14 changed files with 144 additions and 48 deletions
@@ -11,11 +11,6 @@ class AcCubit extends Cubit<AcState> {
static AcCubit get(context) => BlocProvider.of(context);
void selectAC(ACModel model) {
model.isSelected = !model.isSelected;
emit(ACSelected());
}
ACModel? getSelectedAC() {
for (var ac in DevicesCubit.categories[0].devices) {
if (ac is ACModel && ac.isSelected) {
+36 -11
View File
@@ -179,6 +179,17 @@ class DevicesCubit extends Cubit<DevicesState> {
),
];
void selectCategory(int index) {
for (var i = 0; i < categories.length; i++) {
if (i == index) {
categories[i].isSelected = true;
} else {
categories[i].isSelected = false;
}
}
emit(DevicesCategoryChanged());
}
Widget? get chosenCategoryView {
for (var category in categories) {
if (category.isSelected) {
@@ -188,6 +199,31 @@ class DevicesCubit extends Cubit<DevicesState> {
return null;
}
void selectDevice(DeviceModel device) {
for (var category in categories) {
for (var device in category.devices) {
if (device.isSelected) {
category.isSelected = false;
emit(DeviceSelected());
return;
}
}
}
device.isSelected = !device.isSelected;
emit(DeviceSelected());
}
DeviceModel? getSelectedDevice() {
for (var category in categories) {
for (var device in category.devices) {
if (device.isSelected) {
return device;
}
}
}
return null;
}
void changeCategorySwitchValue(DevicesCategoryModel category) {
if (category.devicesStatus != null) {
category.devicesStatus = !category.devicesStatus!;
@@ -252,17 +288,6 @@ class DevicesCubit extends Cubit<DevicesState> {
}
}
void selectCategory(int index) {
for (var i = 0; i < categories.length; i++) {
if (i == index) {
categories[i].isSelected = true;
} else {
categories[i].isSelected = false;
}
}
emit(DevicesCategoryChanged());
}
static void clearCategoriesSelection() {
for (var category in categories) {
category.isSelected = false;
@@ -18,3 +18,5 @@ class DevicesCategoryChanged extends DevicesState {}
class CategorySwitchChanged extends DevicesState {}
class DeviceSwitchChanged extends DevicesState {}
class DeviceSelected extends DevicesState {}