mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-26 03:57:55 +00:00
code refactoring
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user