mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00

AC Cubit Add New Devices Cubit Arch will be used Devices Cubit (for devices categories, and devices page) { AC cubit, Lights cubit. ... } Replaced AssetsManager with Assets Class (auto generated)
131 lines
3.5 KiB
Dart
131 lines
3.5 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/curtain_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/door_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/gateway_view.dart';
|
|
import 'package:syncrow_app/features/devices/view/widgets/screens_view.dart';
|
|
import 'package:syncrow_app/generated/assets.dart';
|
|
|
|
import '../model/device_category_model.dart';
|
|
import '../view/widgets/ac_view.dart';
|
|
import '../view/widgets/lights_view.dart';
|
|
|
|
part 'devices_state.dart';
|
|
|
|
class DevicesCubit extends Cubit<DevicesState> {
|
|
DevicesCubit() : super(DevicesInitial()) {
|
|
// getCategories();
|
|
}
|
|
|
|
/// separate the cubit into different cubits based on devices type
|
|
static bool ACSwitchValue = false;
|
|
static bool lightsSwitchValue = false;
|
|
static bool doorSwitchValue = false;
|
|
static bool curtainSwitchValue = false;
|
|
static bool screensSwitchValue = false;
|
|
static bool gatewaySwitchValue = false;
|
|
|
|
void changeCategorySwitchValue(DevicesCategoryModel category) {
|
|
category.switchValue = !category.switchValue;
|
|
emit(CategorySwitchChanged());
|
|
print('${category.name} switch value: ${category.switchValue} ');
|
|
}
|
|
|
|
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',
|
|
switchValue: ACSwitchValue,
|
|
type: DeviceType.AC,
|
|
page: const ACView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsLight,
|
|
name: 'Lights',
|
|
switchValue: lightsSwitchValue,
|
|
type: DeviceType.Lights,
|
|
page: const LightsView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsDoorLock,
|
|
name: 'Doors',
|
|
switchValue: doorSwitchValue,
|
|
type: DeviceType.Door,
|
|
page: const DoorView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsCurtain,
|
|
name: 'Curtains',
|
|
switchValue: curtainSwitchValue,
|
|
type: DeviceType.Curtain,
|
|
page: const CurtainView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsScreen,
|
|
name: 'Screens',
|
|
switchValue: screensSwitchValue,
|
|
type: DeviceType.Screens,
|
|
page: const ScreensView(),
|
|
),
|
|
DevicesCategoryModel(
|
|
devices: [],
|
|
icon: Assets.iconsGateway,
|
|
name: 'Gateway',
|
|
switchValue: gatewaySwitchValue,
|
|
type: DeviceType.Gateway,
|
|
page: const GateWayView(),
|
|
),
|
|
];
|
|
|
|
Widget? get chosenCategory {
|
|
for (var category in categories) {
|
|
if (category.isSelected) {
|
|
return category.page;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
void updateCategory(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;
|
|
}
|
|
}
|
|
}
|