mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-24 07:27:56 +00:00
AC devices page implemented
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)
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
|
||||
part 'ac_state.dart';
|
||||
|
||||
class AcCubit extends Cubit<AcState> {
|
||||
AcCubit() : super(AcInitial());
|
||||
|
||||
static AcCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
bool areAllACsOff() {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
if (ac.status) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void turnAllACsOff() {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
ac.status = false;
|
||||
}
|
||||
emit(SwitchACsOff());
|
||||
}
|
||||
|
||||
void turnAllACsOn() {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
ac.status = true;
|
||||
}
|
||||
emit(SwitchACsOn());
|
||||
}
|
||||
|
||||
void setTempToAll(double temperature) {
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
ac.temperature = temperature;
|
||||
}
|
||||
emit(ACsTempChanged());
|
||||
}
|
||||
|
||||
double averageTempForAll() {
|
||||
double allTemp = 0;
|
||||
for (var ac in DevicesCubit.categories[0].devices) {
|
||||
allTemp += ac.temperature;
|
||||
}
|
||||
emit(ACsTempChanged());
|
||||
|
||||
double averageTemp = allTemp / DevicesCubit.categories[0].devices.length;
|
||||
|
||||
averageTemp = (averageTemp * 2).round() / 2;
|
||||
|
||||
return averageTemp;
|
||||
}
|
||||
|
||||
/// implement the fan speed and temp mode change
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
part of 'ac_cubit.dart';
|
||||
|
||||
@immutable
|
||||
abstract class AcState {}
|
||||
|
||||
class AcInitial extends AcState {}
|
||||
|
||||
class SwitchACsOff extends AcState {}
|
||||
|
||||
class SwitchACsOn extends AcState {}
|
||||
|
||||
class ACsTempChanged extends AcState {}
|
||||
|
||||
class ACsFanSpeedChanged extends AcState {}
|
||||
|
||||
class ACsTempModeChanged extends AcState {}
|
||||
@@ -1,99 +1,130 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/assets_manager.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();
|
||||
// getCategories();
|
||||
}
|
||||
|
||||
bool ACSwitchValue = false;
|
||||
bool lightsSwitchValue = false;
|
||||
bool doorSwitchValue = false;
|
||||
bool curtainSwitchValue = false;
|
||||
bool screensSwitchValue = false;
|
||||
bool gatewaySwitchValue = false;
|
||||
/// 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 changeSwitchValue(DeviceType device) {
|
||||
switch (device) {
|
||||
case DeviceType.AC:
|
||||
ACSwitchValue = !ACSwitchValue;
|
||||
break;
|
||||
case DeviceType.Lights:
|
||||
lightsSwitchValue = !lightsSwitchValue;
|
||||
break;
|
||||
case DeviceType.Door:
|
||||
doorSwitchValue = !doorSwitchValue;
|
||||
break;
|
||||
case DeviceType.Curtain:
|
||||
curtainSwitchValue = !curtainSwitchValue;
|
||||
break;
|
||||
case DeviceType.Screens:
|
||||
screensSwitchValue = !screensSwitchValue;
|
||||
break;
|
||||
case DeviceType.Gateway:
|
||||
gatewaySwitchValue = !gatewaySwitchValue;
|
||||
break;
|
||||
}
|
||||
emit(DevicesSuccess());
|
||||
void changeCategorySwitchValue(DevicesCategoryModel category) {
|
||||
category.switchValue = !category.switchValue;
|
||||
emit(CategorySwitchChanged());
|
||||
print('${category.name} switch value: ${category.switchValue} ');
|
||||
}
|
||||
|
||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
var categories = <DevicesCategoryModel>[];
|
||||
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(),
|
||||
),
|
||||
];
|
||||
|
||||
Future<List<DevicesCategoryModel>> getCategories() async {
|
||||
emit(DevicesLoading());
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
emit(DevicesSuccess());
|
||||
Widget? get chosenCategory {
|
||||
for (var category in categories) {
|
||||
if (category.isSelected) {
|
||||
return category.page;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
return categories = [
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: IconsManager.ac,
|
||||
name: 'ACs',
|
||||
switchValue: false,
|
||||
type: DeviceType.AC,
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: IconsManager.light,
|
||||
name: 'Lights',
|
||||
switchValue: false,
|
||||
type: DeviceType.Lights,
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: IconsManager.doorLock,
|
||||
name: 'Doors',
|
||||
switchValue: false,
|
||||
type: DeviceType.Door,
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: IconsManager.curtain,
|
||||
name: 'Curtains',
|
||||
switchValue: false,
|
||||
type: DeviceType.Curtain,
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: IconsManager.screen,
|
||||
name: 'Screens',
|
||||
switchValue: false,
|
||||
type: DeviceType.Screens,
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: IconsManager.gateway,
|
||||
name: 'Gateway',
|
||||
switchValue: false,
|
||||
type: DeviceType.Gateway,
|
||||
),
|
||||
];
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,3 +12,13 @@ class DevicesSuccess extends DevicesState {}
|
||||
class DevicesFailure extends DevicesState {}
|
||||
|
||||
class ChangeIndex extends DevicesState {}
|
||||
|
||||
class DevicesCategoryChanged extends DevicesState {}
|
||||
|
||||
class CategorySwitchChanged extends DevicesState {}
|
||||
|
||||
class SwitchACsOff extends DevicesState {}
|
||||
|
||||
class SwitchACsOn extends DevicesState {}
|
||||
|
||||
class SetACsTemp extends DevicesState {}
|
||||
|
||||
Reference in New Issue
Block a user