mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 01:56:19 +00:00
130 lines
3.4 KiB
Dart
130 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/screens/screens_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart';
|
|
import 'package:syncrow_app/generated/assets.dart';
|
|
|
|
import '../model/device_category_model.dart';
|
|
import '../view/widgets/ACs/ac_view.dart';
|
|
import '../view/widgets/lights/lights_view.dart';
|
|
|
|
part 'devices_state.dart';
|
|
|
|
class DevicesCubit extends Cubit<DevicesState> {
|
|
DevicesCubit() : super(DevicesInitial()) {
|
|
// getCategories();
|
|
}
|
|
|
|
void changeCategorySwitchValue(DevicesCategoryModel category) {
|
|
category.devicesStatus = !category.devicesStatus;
|
|
for (var device in category.devices) {
|
|
device.status = category.devicesStatus;
|
|
}
|
|
emit(CategorySwitchChanged());
|
|
print('${category.name} switch value: ${category.devicesStatus} ');
|
|
}
|
|
|
|
static DevicesCubit get(context) => BlocProvider.of(context);
|
|
|
|
static var categories = <DevicesCategoryModel>[
|
|
DevicesCategoryModel(
|
|
devices: [
|
|
ACModel(
|
|
name: "Living Room AC",
|
|
id: '0',
|
|
status: false,
|
|
temperature: 20,
|
|
fanSpeed: 0,
|
|
tempMode: 0,
|
|
),
|
|
ACModel(
|
|
name: "Master Bedroom AC",
|
|
id: '1',
|
|
status: false,
|
|
temperature: 20,
|
|
fanSpeed: 0,
|
|
tempMode: 0,
|
|
),
|
|
],
|
|
icon: Assets.iconsAC,
|
|
name: 'ACs',
|
|
type: DeviceType.AC,
|
|
page: const ACView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsLight,
|
|
name: 'Lights',
|
|
type: DeviceType.Lights,
|
|
page: const LightsView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsDoorLock,
|
|
name: 'Doors',
|
|
type: DeviceType.Door,
|
|
page: const DoorView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsCurtain,
|
|
name: 'Curtains',
|
|
type: DeviceType.Curtain,
|
|
page: const CurtainView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsScreen,
|
|
name: 'Screens',
|
|
type: DeviceType.Screens,
|
|
page: const ScreensView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsGateway,
|
|
name: 'Gateway',
|
|
type: DeviceType.Gateway,
|
|
page: const GateWayView(),
|
|
),
|
|
];
|
|
|
|
Widget? get chosenCategoryView {
|
|
for (var category in categories) {
|
|
if (category.isSelected) {
|
|
return category.page;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
void areAllDevicesOff(DevicesCategoryModel category) {
|
|
for (var device in category.devices) {
|
|
if (device.status) {
|
|
category.devicesStatus = false;
|
|
emit(CategorySwitchChanged());
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|