mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 01:35:23 +00:00
temp
This commit is contained in:
@ -1,56 +0,0 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
|
||||
part 'ac_state.dart';
|
||||
|
||||
class AcCubit extends Cubit<AcState> {
|
||||
AcCubit() : super(AcInitial());
|
||||
|
||||
static AcCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
static DevicesCategoryModel category = DevicesCubit.allCategories[0];
|
||||
|
||||
ACModel? getSelectedAC() {
|
||||
for (var ac in category.devices) {
|
||||
if (ac is ACModel && ac.isSelected) {
|
||||
return ac;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void setTempToAll(double temperature) {
|
||||
for (DeviceModel ac in category.devices) {
|
||||
if (ac is ACModel) {
|
||||
if (ac.temperature != temperature &&
|
||||
ac.bounds.min <= temperature &&
|
||||
temperature <= ac.bounds.max) {
|
||||
setACTemp(ac, temperature);
|
||||
}
|
||||
}
|
||||
}
|
||||
universalACTemp = temperature;
|
||||
emit(ACsTempChanged(temperature));
|
||||
}
|
||||
|
||||
void setACTemp(ACModel model, double temp) {
|
||||
if (model.bounds.min <= temp && temp <= model.bounds.max) {
|
||||
model.temperature = temp;
|
||||
}
|
||||
emit(ACsTempChanged(temp));
|
||||
}
|
||||
|
||||
double getTemp(int index) {
|
||||
var device = category.devices[index];
|
||||
if (device is ACModel) {
|
||||
return device.temperature;
|
||||
}
|
||||
return 0.0; // or any default value you prefer
|
||||
}
|
||||
|
||||
static double universalACTemp = 20;
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
part of 'ac_cubit.dart';
|
||||
|
||||
@immutable
|
||||
abstract class AcState {}
|
||||
|
||||
class AcInitial extends AcState {}
|
||||
|
||||
class ACsStatusChanged extends AcState {}
|
||||
|
||||
class SwitchACsOff extends AcState {}
|
||||
|
||||
class SwitchACsOn extends AcState {}
|
||||
|
||||
class ACsTempChanged extends AcState {
|
||||
final double temperature;
|
||||
|
||||
ACsTempChanged(this.temperature);
|
||||
}
|
||||
|
||||
class ACsAverageTemp extends AcState {}
|
||||
|
||||
class ACsFanSpeedChanged extends AcState {}
|
||||
|
||||
class ACsTempModeChanged extends AcState {}
|
||||
|
||||
class ACTurnedOn extends AcState {}
|
||||
|
||||
class ACTurnedOff extends AcState {}
|
||||
|
||||
class ACSelected extends AcState {}
|
@ -1,13 +0,0 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
|
||||
part 'curtains_state.dart';
|
||||
|
||||
class CurtainsCubit extends Cubit<CurtainsState> {
|
||||
CurtainsCubit() : super(CurtainsInitial());
|
||||
|
||||
static CurtainsCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
static DevicesCategoryModel category = DevicesCubit.allCategories[3];
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
part of 'curtains_cubit.dart';
|
||||
|
||||
abstract class CurtainsState {}
|
||||
|
||||
class CurtainsInitial extends CurtainsState {}
|
@ -1,19 +1,16 @@
|
||||
import 'package:dio/dio.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/model/curtain_model.dart';
|
||||
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.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/lights/lights_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights_switches/light_switches.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_view.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
@ -26,229 +23,229 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
static List<DevicesCategoryModel> allCategories = [
|
||||
DevicesCategoryModel(
|
||||
devices: [
|
||||
ACModel(
|
||||
name: "Living Room AC",
|
||||
id: 0,
|
||||
functions: [],
|
||||
status: false,
|
||||
temperature: 20,
|
||||
fanSpeed: 0,
|
||||
tempMode: 0,
|
||||
coolTo: 20,
|
||||
type: DeviceType.AC,
|
||||
image: '',
|
||||
timer: null,
|
||||
bounds: Bounds(
|
||||
min: 20,
|
||||
max: 30,
|
||||
),
|
||||
),
|
||||
ACModel(
|
||||
name: "Master Bedroom AC",
|
||||
id: 1,
|
||||
functions: [],
|
||||
status: false,
|
||||
temperature: 20,
|
||||
fanSpeed: 0,
|
||||
tempMode: 0,
|
||||
coolTo: 20,
|
||||
type: DeviceType.AC,
|
||||
image: '',
|
||||
timer: null,
|
||||
bounds: Bounds(
|
||||
min: 20,
|
||||
max: 30,
|
||||
),
|
||||
),
|
||||
ACModel(
|
||||
name: "Kitchen AC",
|
||||
id: 2,
|
||||
functions: [],
|
||||
status: false,
|
||||
temperature: 20,
|
||||
fanSpeed: 0,
|
||||
tempMode: 0,
|
||||
coolTo: 20,
|
||||
type: DeviceType.AC,
|
||||
image: '',
|
||||
timer: null,
|
||||
bounds: Bounds(
|
||||
min: 20,
|
||||
max: 30,
|
||||
),
|
||||
),
|
||||
ACModel(
|
||||
name: "Bathroom AC",
|
||||
id: 3,
|
||||
functions: [],
|
||||
status: false,
|
||||
temperature: 20,
|
||||
fanSpeed: 0,
|
||||
tempMode: 0,
|
||||
coolTo: 20,
|
||||
type: DeviceType.AC,
|
||||
image: '',
|
||||
timer: null,
|
||||
bounds: Bounds(
|
||||
min: 20,
|
||||
max: 30,
|
||||
),
|
||||
),
|
||||
],
|
||||
icon: Assets.iconsAC,
|
||||
name: 'ACs',
|
||||
type: DeviceType.AC,
|
||||
page: const ACsView(),
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [
|
||||
LightModel(
|
||||
name: "Living Room Light",
|
||||
id: 0,
|
||||
functions: [],
|
||||
status: false,
|
||||
color: 0,
|
||||
brightness: 20,
|
||||
lightingMode: 1,
|
||||
timer: null,
|
||||
type: DeviceType.Lights,
|
||||
image: '',
|
||||
recentColors: [
|
||||
0xFF83D9FF,
|
||||
0xFFFC3E81,
|
||||
0xFFC0FF66,
|
||||
0xFFFDC242,
|
||||
],
|
||||
),
|
||||
LightModel(
|
||||
name: "Master Bedroom Light",
|
||||
id: 1,
|
||||
functions: [],
|
||||
status: false,
|
||||
color: 2,
|
||||
brightness: 40,
|
||||
lightingMode: 1,
|
||||
timer: null,
|
||||
type: DeviceType.Lights,
|
||||
image: '',
|
||||
recentColors: [
|
||||
0xFF83D9FF,
|
||||
0xFFFC3E81,
|
||||
0xFFC0FF66,
|
||||
0xFFFDC242,
|
||||
],
|
||||
),
|
||||
LightModel(
|
||||
name: "Kitchen Light",
|
||||
id: 2,
|
||||
functions: [],
|
||||
status: false,
|
||||
color: 1,
|
||||
brightness: 60,
|
||||
lightingMode: 1,
|
||||
timer: null,
|
||||
type: DeviceType.Lights,
|
||||
image: '',
|
||||
recentColors: [
|
||||
0xFF83D9FF,
|
||||
0xFFFC3E81,
|
||||
0xFFC0FF66,
|
||||
0xFFFDC242,
|
||||
],
|
||||
),
|
||||
LightModel(
|
||||
name: "Bathroom Light",
|
||||
id: 3,
|
||||
functions: [],
|
||||
status: false,
|
||||
color: 3,
|
||||
brightness: 80,
|
||||
lightingMode: 1,
|
||||
timer: null,
|
||||
type: DeviceType.Lights,
|
||||
image: '',
|
||||
recentColors: [
|
||||
0xFF83D9FF,
|
||||
0xFFFC3E81,
|
||||
0xFFC0FF66,
|
||||
0xFFFDC242,
|
||||
],
|
||||
),
|
||||
LightModel(
|
||||
name: "Balcony Light",
|
||||
id: 4,
|
||||
functions: [],
|
||||
status: false,
|
||||
color: 4,
|
||||
brightness: 100,
|
||||
lightingMode: 1,
|
||||
timer: null,
|
||||
type: DeviceType.Lights,
|
||||
image: '',
|
||||
recentColors: [
|
||||
0xFF83D9FF,
|
||||
0xFFFC3E81,
|
||||
0xFFC0FF66,
|
||||
0xFFFDC242,
|
||||
],
|
||||
),
|
||||
],
|
||||
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: [
|
||||
CurtainModel(
|
||||
openPercentage: 10,
|
||||
id: 1,
|
||||
functions: [],
|
||||
name: "Living Room Curtain",
|
||||
status: false,
|
||||
type: DeviceType.Curtain,
|
||||
image: '',
|
||||
timer: null,
|
||||
),
|
||||
CurtainModel(
|
||||
openPercentage: 20,
|
||||
id: 2,
|
||||
functions: [],
|
||||
name: "Master Bedroom Curtain",
|
||||
status: false,
|
||||
type: DeviceType.Curtain,
|
||||
image: '',
|
||||
timer: null,
|
||||
),
|
||||
],
|
||||
icon: Assets.iconsCurtain,
|
||||
name: 'Curtains',
|
||||
type: DeviceType.Curtain,
|
||||
page: const CurtainView(),
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: Assets.icons3GangSwitch,
|
||||
name: 'Bedroom Lights',
|
||||
type: DeviceType.ThreeGang,
|
||||
page: const LightSwitchesView(),
|
||||
),
|
||||
DevicesCategoryModel(
|
||||
devices: [],
|
||||
icon: Assets.iconsGateway,
|
||||
name: 'Gateway',
|
||||
type: DeviceType.Gateway,
|
||||
page: const GateWayView(),
|
||||
),
|
||||
// DevicesCategoryModel(
|
||||
// devices: [
|
||||
// DeviceModel(
|
||||
// name: "Living Room AC",
|
||||
// id: 0,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// temperature: 20,
|
||||
// fanSpeed: 0,
|
||||
// tempMode: 0,
|
||||
// coolTo: 20,
|
||||
// type: DeviceType.AC,
|
||||
// image: '',
|
||||
// timer: null,
|
||||
// bounds: Bounds(
|
||||
// min: 20,
|
||||
// max: 30,
|
||||
// ),
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// name: "Master Bedroom AC",
|
||||
// id: 1,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// temperature: 20,
|
||||
// fanSpeed: 0,
|
||||
// tempMode: 0,
|
||||
// coolTo: 20,
|
||||
// type: DeviceType.AC,
|
||||
// image: '',
|
||||
// timer: null,
|
||||
// bounds: Bounds(
|
||||
// min: 20,
|
||||
// max: 30,
|
||||
// ),
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// name: "Kitchen AC",
|
||||
// id: 2,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// temperature: 20,
|
||||
// fanSpeed: 0,
|
||||
// tempMode: 0,
|
||||
// coolTo: 20,
|
||||
// type: DeviceType.AC,
|
||||
// image: '',
|
||||
// timer: null,
|
||||
// bounds: Bounds(
|
||||
// min: 20,
|
||||
// max: 30,
|
||||
// ),
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// name: "Bathroom AC",
|
||||
// id: 3,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// temperature: 20,
|
||||
// fanSpeed: 0,
|
||||
// tempMode: 0,
|
||||
// coolTo: 20,
|
||||
// type: DeviceType.AC,
|
||||
// image: '',
|
||||
// timer: null,
|
||||
// bounds: Bounds(
|
||||
// min: 20,
|
||||
// max: 30,
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// icon: Assets.iconsAC,
|
||||
// name: 'ACs',
|
||||
// type: DeviceType.AC,
|
||||
// page: const ACsView(),
|
||||
// ),
|
||||
// DevicesCategoryModel(
|
||||
// devices: [
|
||||
// DeviceModel(
|
||||
// name: "Living Room Light",
|
||||
// id: 0,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// color: 0,
|
||||
// brightness: 20,
|
||||
// lightingMode: 1,
|
||||
// timer: null,
|
||||
// type: DeviceType.Lights,
|
||||
// image: '',
|
||||
// recentColors: [
|
||||
// 0xFF83D9FF,
|
||||
// 0xFFFC3E81,
|
||||
// 0xFFC0FF66,
|
||||
// 0xFFFDC242,
|
||||
// ],
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// name: "Master Bedroom Light",
|
||||
// id: 1,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// color: 2,
|
||||
// brightness: 40,
|
||||
// lightingMode: 1,
|
||||
// timer: null,
|
||||
// type: DeviceType.Lights,
|
||||
// image: '',
|
||||
// recentColors: [
|
||||
// 0xFF83D9FF,
|
||||
// 0xFFFC3E81,
|
||||
// 0xFFC0FF66,
|
||||
// 0xFFFDC242,
|
||||
// ],
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// name: "Kitchen Light",
|
||||
// id: 2,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// color: 1,
|
||||
// brightness: 60,
|
||||
// lightingMode: 1,
|
||||
// timer: null,
|
||||
// type: DeviceType.Lights,
|
||||
// image: '',
|
||||
// recentColors: [
|
||||
// 0xFF83D9FF,
|
||||
// 0xFFFC3E81,
|
||||
// 0xFFC0FF66,
|
||||
// 0xFFFDC242,
|
||||
// ],
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// name: "Bathroom Light",
|
||||
// id: 3,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// color: 3,
|
||||
// brightness: 80,
|
||||
// lightingMode: 1,
|
||||
// timer: null,
|
||||
// type: DeviceType.Lights,
|
||||
// image: '',
|
||||
// recentColors: [
|
||||
// 0xFF83D9FF,
|
||||
// 0xFFFC3E81,
|
||||
// 0xFFC0FF66,
|
||||
// 0xFFFDC242,
|
||||
// ],
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// name: "Balcony Light",
|
||||
// id: 4,
|
||||
// functions: [],
|
||||
// status: false,
|
||||
// color: 4,
|
||||
// brightness: 100,
|
||||
// lightingMode: 1,
|
||||
// timer: null,
|
||||
// type: DeviceType.Lights,
|
||||
// image: '',
|
||||
// recentColors: [
|
||||
// 0xFF83D9FF,
|
||||
// 0xFFFC3E81,
|
||||
// 0xFFC0FF66,
|
||||
// 0xFFFDC242,
|
||||
// ],
|
||||
// ),
|
||||
// ],
|
||||
// icon: Assets.iconsLight,
|
||||
// name: 'Lights',
|
||||
// type: DeviceType.Lights,
|
||||
// page: const LightsView(),
|
||||
// ),
|
||||
// DevicesCategoryModel(
|
||||
// devices: [],
|
||||
// icon: Assets.iconsDoorLock,
|
||||
// name: 'Doors',
|
||||
// type: DeviceType.DoorLock,
|
||||
// page: const DoorView(),
|
||||
// ),
|
||||
// DevicesCategoryModel(
|
||||
// devices: [
|
||||
// DeviceModel(
|
||||
// openPercentage: 10,
|
||||
// id: 1,
|
||||
// functions: [],
|
||||
// name: "Living Room Curtain",
|
||||
// status: false,
|
||||
// type: DeviceType.Curtain,
|
||||
// image: '',
|
||||
// timer: null,
|
||||
// ),
|
||||
// DeviceModel(
|
||||
// openPercentage: 20,
|
||||
// id: 2,
|
||||
// functions: [],
|
||||
// name: "Master Bedroom Curtain",
|
||||
// status: false,
|
||||
// type: DeviceType.Curtain,
|
||||
// image: '',
|
||||
// timer: null,
|
||||
// ),
|
||||
// ],
|
||||
// icon: Assets.iconsCurtain,
|
||||
// name: 'Curtains',
|
||||
// type: DeviceType.Curtain,
|
||||
// page: const CurtainView(),
|
||||
// ),
|
||||
// DevicesCategoryModel(
|
||||
// devices: [],
|
||||
// icon: Assets.icons3GangSwitch,
|
||||
// name: 'Bedroom Lights',
|
||||
// type: DeviceType.ThreeGang,
|
||||
// page: const LightSwitchesView(),
|
||||
// ),
|
||||
// DevicesCategoryModel(
|
||||
// devices: [],
|
||||
// icon: Assets.iconsGateway,
|
||||
// name: 'Gateway',
|
||||
// type: DeviceType.Gateway,
|
||||
// page: const GateWayView(),
|
||||
// ),
|
||||
];
|
||||
|
||||
selectCategory(int index) {
|
||||
@ -272,7 +269,22 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
Widget? get chosenCategoryView {
|
||||
for (var category in allCategories) {
|
||||
if (category.isSelected) {
|
||||
return category.page;
|
||||
switch (category.type) {
|
||||
case DeviceType.AC:
|
||||
return const ACsView();
|
||||
case DeviceType.Lights:
|
||||
return const LightsView();
|
||||
case DeviceType.DoorLock:
|
||||
return const DoorView();
|
||||
case DeviceType.Curtain:
|
||||
return const CurtainView();
|
||||
case DeviceType.ThreeGang:
|
||||
return const LightSwitchesView();
|
||||
case DeviceType.Gateway:
|
||||
return const GateWayView();
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -289,7 +301,8 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
selectDevice(DeviceModel device) {
|
||||
for (var category in allCategories) {
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
if (device.isSelected) {
|
||||
category.isSelected = false;
|
||||
emit(DeviceSelected());
|
||||
@ -297,33 +310,40 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
device.isSelected = !device.isSelected;
|
||||
emit(DeviceSelected());
|
||||
}
|
||||
|
||||
DeviceModel? getSelectedDevice() {
|
||||
for (var category in allCategories) {
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
if (device.isSelected) {
|
||||
return device;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
changeCategorySwitchValue(DevicesCategoryModel category) {
|
||||
if (category.devicesStatus != null) {
|
||||
category.devicesStatus = !category.devicesStatus!;
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = category.devicesStatus;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
category.devicesStatus = true;
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
updateDevicesStatus(category);
|
||||
|
||||
emit(CategorySwitchChanged());
|
||||
@ -331,16 +351,22 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
turnOnOffDevice(DeviceModel device) {
|
||||
device.status = !device.status!;
|
||||
DevicesCategoryModel category = allCategories
|
||||
.firstWhere((category) => category.devices.contains(device));
|
||||
DevicesCategoryModel category = allCategories.firstWhere((category) {
|
||||
if (category.devices != null) {
|
||||
return category.devices!.contains(device);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
updateDevicesStatus(category);
|
||||
emit(DeviceSwitchChanged());
|
||||
}
|
||||
|
||||
updateDevicesStatus(DevicesCategoryModel category) {
|
||||
if (category.devices.isNotEmpty) {
|
||||
bool? tempStatus = category.devices[0].status;
|
||||
for (var ac in category.devices) {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
bool? tempStatus = category.devices![0].status;
|
||||
for (var ac in category.devices!) {
|
||||
//check if there any ac have a different status than the initial ==> turn off the universal switch
|
||||
if (ac.status != tempStatus) {
|
||||
category.devicesStatus = null;
|
||||
@ -355,10 +381,12 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
emit(DeviceSwitchChanged());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
turnAllDevicesOff(DevicesCategoryModel category) {
|
||||
if (category.devices.isNotEmpty) {
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = false;
|
||||
}
|
||||
changeCategorySwitchValue(category);
|
||||
@ -366,10 +394,12 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
emit(CategorySwitchChanged());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
turnAllDevicesOn(DevicesCategoryModel category) {
|
||||
if (category.devices.isNotEmpty) {
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
if (category.devices!.isNotEmpty) {
|
||||
for (var device in category.devices!) {
|
||||
device.status = true;
|
||||
}
|
||||
changeCategorySwitchValue(category);
|
||||
@ -377,9 +407,11 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
emit(CategorySwitchChanged());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
areAllDevicesOff(DevicesCategoryModel category) {
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
if (device.status ?? false) {
|
||||
category.devicesStatus = false;
|
||||
emit(CategorySwitchChanged());
|
||||
@ -387,14 +419,17 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clearCategoriesSelection(BuildContext context) {
|
||||
for (var category in allCategories) {
|
||||
category.isSelected = false;
|
||||
for (var device in category.devices) {
|
||||
if (category.devices != null) {
|
||||
for (var device in category.devices!) {
|
||||
device.isSelected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Navigator.popUntil(context, (route) => route.isFirst);
|
||||
|
||||
emit(DevicesCategoryChanged());
|
||||
@ -422,4 +457,108 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
emit(DeviceControlError(ServerFailure.fromDioError(e).errMessage));
|
||||
}
|
||||
}
|
||||
|
||||
fetchGroups(
|
||||
SpaceModel space,
|
||||
) async {
|
||||
emit(DevicesCategoriesLoading());
|
||||
try {
|
||||
allCategories = await DevicesAPI.fetchGroups(space.id!);
|
||||
emit(DevicesCategoriesSuccess());
|
||||
} on DioException catch (e) {
|
||||
emit(DevicesCategoriesError(ServerFailure.fromDioError(e).errMessage));
|
||||
}
|
||||
}
|
||||
|
||||
///Lights
|
||||
onHorizontalDragUpdate(DeviceModel light, double dx, double screenWidth) {
|
||||
double newBrightness = (dx / (screenWidth - 15) * 100);
|
||||
if (newBrightness > 100) {
|
||||
newBrightness = 100;
|
||||
} else if (newBrightness < 0) {
|
||||
newBrightness = 0;
|
||||
}
|
||||
// setBrightness(light, newBrightness);
|
||||
}
|
||||
|
||||
Map<int, LightMode> lightModes = {
|
||||
0: LightMode.Doze,
|
||||
1: LightMode.Relax,
|
||||
2: LightMode.Reading,
|
||||
3: LightMode.Energizing,
|
||||
};
|
||||
|
||||
// setLightingMode(DeviceModel light, LightMode mode) {
|
||||
// light.lightingMode =
|
||||
// lightModes.entries.firstWhere((element) => element.value == mode).key;
|
||||
// emit(LightModeChanged(mode));
|
||||
// }
|
||||
//
|
||||
// toggleLight(DeviceModel light) {
|
||||
// light.status != null ? light.status = !light.status! : light.status = true;
|
||||
// emit(LightToggled(light));
|
||||
// }
|
||||
//
|
||||
// setColor(DeviceModel light, int color) {
|
||||
// light.color = color;
|
||||
// emit(LightColorChanged(color));
|
||||
// }
|
||||
//
|
||||
// int getBrightness(DeviceModel light) {
|
||||
// return light.brightness.toInt();
|
||||
// }
|
||||
|
||||
// setBrightness(DeviceModel light, double value) {
|
||||
// value = (value / 5).ceil() * 5;
|
||||
// if (value != light.brightness) {
|
||||
// light.brightness = value;
|
||||
// emit(LightBrightnessChanged(value));
|
||||
// }
|
||||
// }
|
||||
|
||||
///ACs
|
||||
// DeviceModel? getSelectedAC() {
|
||||
// for (var ac in category.devices) {
|
||||
// if (ac is DeviceModel && ac.isSelected) {
|
||||
// return ac;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// void setTempToAll(double temperature) {
|
||||
// for (DeviceModel ac in category.devices) {
|
||||
// if (ac is DeviceModel) {
|
||||
// if (ac.temperature != temperature &&
|
||||
// ac.bounds.min <= temperature &&
|
||||
// temperature <= ac.bounds.max) {
|
||||
// setACTemp(ac, temperature);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// universalACTemp = temperature;
|
||||
// emit(ACsTempChanged(temperature));
|
||||
// }
|
||||
//
|
||||
// void setACTemp(DeviceModel model, double temp) {
|
||||
// if (model.bounds.min <= temp && temp <= model.bounds.max) {
|
||||
// model.temperature = temp;
|
||||
// }
|
||||
// emit(ACsTempChanged(temp));
|
||||
// }
|
||||
//
|
||||
// double getTemp(int index) {
|
||||
// var device = category.devices[index];
|
||||
// if (device is DeviceModel) {
|
||||
// return device.temperature;
|
||||
// }
|
||||
// return 0.0; // or any default value you prefer
|
||||
// }
|
||||
}
|
||||
|
||||
enum LightMode {
|
||||
Doze,
|
||||
Relax,
|
||||
Reading,
|
||||
Energizing,
|
||||
}
|
||||
|
@ -30,3 +30,13 @@ class DeviceControlError extends DevicesState {
|
||||
|
||||
DeviceControlError(this.errorMsg);
|
||||
}
|
||||
|
||||
class DevicesCategoriesLoading extends DevicesState {}
|
||||
|
||||
class DevicesCategoriesSuccess extends DevicesState {}
|
||||
|
||||
class DevicesCategoriesError extends DevicesState {
|
||||
final String errorMsg;
|
||||
|
||||
DevicesCategoriesError(this.errorMsg);
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
|
||||
part 'lights_state.dart';
|
||||
|
||||
class LightsCubit extends Cubit<LightsState> {
|
||||
LightsCubit() : super(LightsInitial());
|
||||
|
||||
static LightsCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
Map<int, LightMode> lightModes = {
|
||||
0: LightMode.doze,
|
||||
1: LightMode.relax,
|
||||
2: LightMode.reading,
|
||||
3: LightMode.energizing,
|
||||
};
|
||||
|
||||
setLightingMode(LightModel light, LightMode mode) {
|
||||
light.lightingMode =
|
||||
lightModes.entries.firstWhere((element) => element.value == mode).key;
|
||||
emit(LightModeChanged(mode));
|
||||
}
|
||||
|
||||
toggleLight(LightModel light) {
|
||||
light.status != null ? light.status = !light.status! : light.status = true;
|
||||
emit(LightToggled(light));
|
||||
}
|
||||
|
||||
setColor(LightModel light, int color) {
|
||||
light.color = color;
|
||||
emit(LightColorChanged(color));
|
||||
}
|
||||
|
||||
int getBrightness(LightModel light) {
|
||||
return light.brightness.toInt();
|
||||
}
|
||||
|
||||
setBrightness(LightModel light, double value) {
|
||||
value = (value / 5).ceil() * 5;
|
||||
if (value != light.brightness) {
|
||||
light.brightness = value;
|
||||
emit(LightBrightnessChanged(value));
|
||||
}
|
||||
}
|
||||
|
||||
onHorizontalDragUpdate(LightModel light, double dx, double screenWidth) {
|
||||
double newBrightness = (dx / (screenWidth - 15) * 100);
|
||||
if (newBrightness > 100) {
|
||||
newBrightness = 100;
|
||||
} else if (newBrightness < 0) {
|
||||
newBrightness = 0;
|
||||
}
|
||||
setBrightness(light, newBrightness);
|
||||
}
|
||||
}
|
||||
|
||||
enum LightMode {
|
||||
doze,
|
||||
relax,
|
||||
reading,
|
||||
energizing,
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
part of 'lights_cubit.dart';
|
||||
|
||||
abstract class LightsState {}
|
||||
|
||||
class LightsInitial extends LightsState {}
|
||||
|
||||
class LightsLoading extends LightsState {}
|
||||
|
||||
class LightsSuccess extends LightsState {}
|
||||
|
||||
class LightsFailure extends LightsState {
|
||||
final String message;
|
||||
|
||||
LightsFailure(this.message);
|
||||
}
|
||||
|
||||
class LightBrightnessChanged extends LightsState {
|
||||
final double brightness;
|
||||
|
||||
LightBrightnessChanged(this.brightness);
|
||||
}
|
||||
|
||||
class LightToggled extends LightsState {
|
||||
final LightModel light;
|
||||
|
||||
LightToggled(this.light);
|
||||
}
|
||||
|
||||
class LightColorChanged extends LightsState {
|
||||
final int color;
|
||||
|
||||
LightColorChanged(this.color);
|
||||
}
|
||||
|
||||
class LightModeChanged extends LightsState {
|
||||
final LightMode mode;
|
||||
|
||||
LightModeChanged(this.mode);
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
|
||||
class ACModel extends DeviceModel {
|
||||
late double temperature;
|
||||
|
||||
late int fanSpeed;
|
||||
|
||||
late int tempMode;
|
||||
|
||||
late double coolTo;
|
||||
|
||||
late Bounds bounds;
|
||||
|
||||
ACModel({
|
||||
required this.temperature,
|
||||
required this.fanSpeed,
|
||||
required this.tempMode,
|
||||
required this.coolTo,
|
||||
required this.bounds,
|
||||
required super.id,
|
||||
required super.name,
|
||||
required super.type,
|
||||
required super.status,
|
||||
required super.image,
|
||||
required super.timer,
|
||||
required super.functions,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'temperature': temperature,
|
||||
'fanSpeed': fanSpeed,
|
||||
'tempMode': tempMode,
|
||||
'coolTo': coolTo,
|
||||
'id': id,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'type': type,
|
||||
'image': image,
|
||||
};
|
||||
}
|
||||
|
||||
factory ACModel.fromJson(Map<String, dynamic> json) {
|
||||
List<FunctionModel> func = [];
|
||||
if (json['functions'] != null) {
|
||||
json['functions'].forEach((v) {
|
||||
func.add(FunctionModel.fromJson(v));
|
||||
});
|
||||
}
|
||||
return ACModel(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
status: json['status'],
|
||||
temperature: json['temperature'],
|
||||
fanSpeed: json['fanSpeed'],
|
||||
tempMode: json['tempMode'],
|
||||
type: json['type'],
|
||||
image: json['image'],
|
||||
timer: json['timer'],
|
||||
coolTo: json['coolTo'],
|
||||
bounds: Bounds.fromJson(json['bounds']),
|
||||
functions: func,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Bounds {
|
||||
late double min;
|
||||
late double max;
|
||||
|
||||
Bounds({
|
||||
required this.min,
|
||||
required this.max,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'min': min,
|
||||
'max': max,
|
||||
};
|
||||
}
|
||||
|
||||
factory Bounds.fromJson(Map<String, dynamic> json) {
|
||||
return Bounds(
|
||||
min: json['min'],
|
||||
max: json['max'],
|
||||
);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
|
||||
class CurtainModel extends DeviceModel {
|
||||
late int openPercentage;
|
||||
|
||||
CurtainModel({
|
||||
required this.openPercentage,
|
||||
required super.id,
|
||||
required super.name,
|
||||
required super.type,
|
||||
required super.status,
|
||||
required super.image,
|
||||
required super.timer,
|
||||
required super.functions,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'openPercentage': openPercentage,
|
||||
'timer': timer,
|
||||
'id': id,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'type': type,
|
||||
'image': image,
|
||||
};
|
||||
}
|
||||
|
||||
factory CurtainModel.fromJson(Map<String, dynamic> json) {
|
||||
List<FunctionModel> func = [];
|
||||
if (json['functions'] != null) {
|
||||
json['functions'].forEach((v) {
|
||||
func.add(FunctionModel.fromJson(v));
|
||||
});
|
||||
}
|
||||
return CurtainModel(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
status: json['status'],
|
||||
openPercentage: json['openPercentage'],
|
||||
timer: json['timer'],
|
||||
type: json['type'],
|
||||
image: json['image'],
|
||||
functions: func,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,32 +1,30 @@
|
||||
// ignore_for_file: constant_identifier_names
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class DevicesCategoryModel {
|
||||
final String name;
|
||||
final String icon;
|
||||
|
||||
final Widget page;
|
||||
int? id;
|
||||
final String? name;
|
||||
final String? icon;
|
||||
|
||||
bool? devicesStatus;
|
||||
final List<DeviceModel> devices;
|
||||
final List<DeviceModel>? devices;
|
||||
|
||||
final DeviceType type;
|
||||
final DeviceType? type;
|
||||
bool isSelected;
|
||||
|
||||
DevicesCategoryModel(
|
||||
{this.isSelected = false,
|
||||
required this.page,
|
||||
required this.type,
|
||||
required this.name,
|
||||
required this.icon,
|
||||
required this.devices}) {
|
||||
//sets the initial status of the devices
|
||||
if (devices.isNotEmpty) {
|
||||
bool tempStatus = devices.first.status ?? false;
|
||||
for (var device in devices) {
|
||||
if (devices != null) {
|
||||
if (devices!.isNotEmpty) {
|
||||
bool tempStatus = devices!.first.status ?? false;
|
||||
for (var device in devices!) {
|
||||
if (device.status != tempStatus) {
|
||||
devicesStatus = false;
|
||||
break;
|
||||
@ -34,5 +32,24 @@ class DevicesCategoryModel {
|
||||
}
|
||||
devicesStatus = tempStatus;
|
||||
}
|
||||
} else {
|
||||
devicesStatus = false;
|
||||
}
|
||||
}
|
||||
|
||||
DevicesCategoryModel.fromJson(Map<String, dynamic> json)
|
||||
: name = json['groupName'],
|
||||
id = json['groupId'],
|
||||
icon = json['icon'],
|
||||
type = deviceTypeMap[json['groupName']] ?? DeviceType.Other,
|
||||
devices = [],
|
||||
isSelected = false;
|
||||
}
|
||||
|
||||
Map<String, DeviceType> deviceTypeMap = {
|
||||
'Ceiling Presence Sensors': DeviceType.Sensors,
|
||||
'Wall presence sensor': DeviceType.Sensors,
|
||||
'Door Locks': DeviceType.DoorLock,
|
||||
'Gateways': DeviceType.Gateway,
|
||||
'ACs': DeviceType.AC,
|
||||
};
|
||||
|
@ -30,7 +30,7 @@ class DeviceModel {
|
||||
case DeviceType.Lights:
|
||||
icon = Assets.iconsLight;
|
||||
break;
|
||||
case DeviceType.Door:
|
||||
case DeviceType.DoorLock:
|
||||
icon = Assets.iconsDoorLock;
|
||||
break;
|
||||
case DeviceType.Curtain:
|
||||
|
@ -1,62 +0,0 @@
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/function_model.dart';
|
||||
|
||||
class LightModel extends DeviceModel {
|
||||
late double brightness;
|
||||
late int color;
|
||||
|
||||
late int lightingMode;
|
||||
|
||||
late List<int> recentColors;
|
||||
|
||||
LightModel({
|
||||
required this.brightness,
|
||||
required this.color,
|
||||
required this.lightingMode,
|
||||
required this.recentColors,
|
||||
required super.id,
|
||||
required super.name,
|
||||
required super.type,
|
||||
required super.status,
|
||||
required super.image,
|
||||
required super.timer,
|
||||
required super.functions,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'luminance': brightness,
|
||||
'color': color,
|
||||
'lightingMode': lightingMode,
|
||||
'timer': timer,
|
||||
'recentColors': recentColors,
|
||||
'id': id,
|
||||
'name': name,
|
||||
'status': status,
|
||||
'type': type,
|
||||
'image': image,
|
||||
};
|
||||
}
|
||||
|
||||
factory LightModel.fromJson(Map<String, dynamic> json) {
|
||||
List<FunctionModel> func = [];
|
||||
if (json['functions'] != null) {
|
||||
json['functions'].forEach((v) {
|
||||
func.add(FunctionModel.fromJson(v));
|
||||
});
|
||||
}
|
||||
return LightModel(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
status: json['status'],
|
||||
brightness: json['luminance'],
|
||||
color: json['color'],
|
||||
lightingMode: json['lightingMode'],
|
||||
timer: json['timer'],
|
||||
type: json['type'],
|
||||
image: json['image'],
|
||||
recentColors: json['recentColors'],
|
||||
functions: func,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface_controls.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
@ -10,9 +10,9 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||
|
||||
class AcInterface extends StatelessWidget {
|
||||
const AcInterface({super.key, required this.acModel});
|
||||
const AcInterface({super.key, required this.deviceModel});
|
||||
|
||||
final ACModel acModel;
|
||||
final DeviceModel deviceModel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -30,7 +30,7 @@ class AcInterface extends StatelessWidget {
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: BodyLarge(
|
||||
text: acModel.name ?? "",
|
||||
text: deviceModel.name ?? "",
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
fontWeight: FontsManager.bold,
|
||||
),
|
||||
@ -62,7 +62,7 @@ class AcInterface extends StatelessWidget {
|
||||
maxHeight: 380,
|
||||
),
|
||||
child: AcInterfaceTempUnit(
|
||||
acModel: acModel,
|
||||
deviceModel: deviceModel,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
@ -73,7 +73,7 @@ class AcInterface extends StatelessWidget {
|
||||
maxHeight: 120,
|
||||
),
|
||||
child: AcInterfaceControls(
|
||||
acModel: acModel,
|
||||
deviceModel: deviceModel,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
|
||||
@ -9,16 +9,16 @@ import '../../../../../generated/assets.dart';
|
||||
class AcInterfaceControls extends StatelessWidget {
|
||||
const AcInterfaceControls({
|
||||
super.key,
|
||||
required this.acModel,
|
||||
required this.deviceModel,
|
||||
});
|
||||
|
||||
final ACModel acModel;
|
||||
final DeviceModel deviceModel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
ACModeControlUnit(model: acModel),
|
||||
ACModeControlUnit(model: deviceModel),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
|
@ -2,7 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:sleek_circular_slider/sleek_circular_slider.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
@ -11,21 +12,19 @@ import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||
|
||||
import '../../../model/ac_model.dart';
|
||||
|
||||
class AcInterfaceTempUnit extends StatelessWidget {
|
||||
const AcInterfaceTempUnit({
|
||||
super.key,
|
||||
required this.acModel,
|
||||
required this.deviceModel,
|
||||
});
|
||||
|
||||
final ACModel acModel;
|
||||
final DeviceModel deviceModel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => AcCubit(),
|
||||
child: BlocBuilder<AcCubit, AcState>(
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
child: Column(
|
||||
@ -55,7 +54,8 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
fontWeight: FontsManager.regular,
|
||||
),
|
||||
modifier: (double value) {
|
||||
return '${acModel.temperature.toStringAsFixed(1)}°C';
|
||||
// return '${DeviceModel.temperature.toStringAsFixed(1)}°C';
|
||||
return '${value.toStringAsFixed(1)}°C';
|
||||
},
|
||||
mainLabelStyle: context.titleLarge.copyWith(
|
||||
height: 0,
|
||||
@ -72,15 +72,16 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
min: acModel.bounds.min,
|
||||
max: acModel.bounds.max,
|
||||
initialValue: acModel.temperature,
|
||||
// min: DeviceModel.bounds.min,
|
||||
// max: DeviceModel.bounds.max,
|
||||
// initialValue: DeviceModel.temperature,
|
||||
onChange: (value) {
|
||||
String valueAsString = value.toStringAsFixed(1);
|
||||
if (valueAsString.endsWith(".0") ||
|
||||
valueAsString.endsWith(".5")) {
|
||||
value = double.parse(valueAsString);
|
||||
AcCubit.get(context).setACTemp(acModel, value);
|
||||
// DevicesCubit.get(context)
|
||||
// .setACTemp(DeviceModel, value);
|
||||
}
|
||||
},
|
||||
),
|
||||
@ -95,9 +96,9 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context)
|
||||
.setACTemp(acModel, acModel.coolTo);
|
||||
acModel.coolTo -= .5;
|
||||
// DevicesCubit.get(context)
|
||||
// .setACTemp(DeviceModel, DeviceModel.coolTo);
|
||||
// DeviceModel.coolTo -= .5;
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsMinus,
|
||||
@ -107,7 +108,8 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
Column(
|
||||
children: [
|
||||
BodyLarge(
|
||||
text: "${acModel.coolTo}° C",
|
||||
// text: "${DeviceModel.coolTo}° C",
|
||||
text: '24° C',
|
||||
style: context.bodyLarge.copyWith(
|
||||
color:
|
||||
ColorsManager.primaryColor.withOpacity(0.6),
|
||||
@ -125,9 +127,9 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context)
|
||||
.setACTemp(acModel, acModel.coolTo);
|
||||
acModel.coolTo += .5;
|
||||
// DevicesCubit.get(context)
|
||||
// .setACTemp(DeviceModel, DeviceModel.coolTo);
|
||||
// DeviceModel.coolTo += .5;
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsPlus,
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
|
||||
import '../../../../../generated/assets.dart';
|
||||
@ -11,7 +10,7 @@ class ACModeControlUnit extends StatefulWidget {
|
||||
required this.model,
|
||||
});
|
||||
|
||||
final ACModel model;
|
||||
final DeviceModel model;
|
||||
|
||||
@override
|
||||
State<ACModeControlUnit> createState() => _ACModeControlUnitState();
|
||||
@ -40,14 +39,14 @@ class _ACModeControlUnitState extends State<ACModeControlUnit> {
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
widget.model.fanSpeed =
|
||||
widget.model.fanSpeed == 3 ? 0 : widget.model.fanSpeed + 1;
|
||||
// widget.model.fanSpeed =
|
||||
// widget.model.fanSpeed == 3 ? 0 : widget.model.fanSpeed + 1;
|
||||
});
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: SvgPicture.asset(fanSpeeds[widget.model.fanSpeed]),
|
||||
// child: SvgPicture.asset(fanSpeeds[widget.model.fanSpeed]),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -57,14 +56,15 @@ class _ACModeControlUnitState extends State<ACModeControlUnit> {
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
widget.model.tempMode =
|
||||
widget.model.tempMode == 2 ? 0 : widget.model.tempMode + 1;
|
||||
// widget.model.tempMode =
|
||||
// widget.model.tempMode == 2 ? 0 : widget.model.tempMode + 1;
|
||||
});
|
||||
},
|
||||
child: DefaultContainer(
|
||||
child: const DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: SvgPicture.asset(tempModes[widget.model.tempMode]),
|
||||
// child: SvgPicture.asset(tempModes[widget.model.tempMode]),
|
||||
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -1,25 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart';import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
import '../../../../../generated/assets.dart';
|
||||
import '../../../model/ac_model.dart';
|
||||
|
||||
class ACTempWidget extends StatelessWidget {
|
||||
const ACTempWidget(
|
||||
this.acModel, {
|
||||
this.deviceModel, {
|
||||
super.key,
|
||||
});
|
||||
|
||||
final ACModel acModel;
|
||||
final DeviceModel deviceModel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AcCubit, AcState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
height: 60,
|
||||
@ -30,8 +31,8 @@ class ACTempWidget extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context)
|
||||
.setACTemp(acModel, acModel.temperature - 0.5);
|
||||
// DevicesCubit.get(context)
|
||||
// .setACTemp(DeviceModel, DeviceModel.temperature - 0.5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsMinus,
|
||||
@ -39,7 +40,8 @@ class ACTempWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
text: "${acModel.temperature}° C",
|
||||
// text: "${DeviceModel.temperature}° C",
|
||||
text: '25 °C',
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontSize: 23,
|
||||
@ -49,8 +51,8 @@ class ACTempWidget extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context)
|
||||
.setACTemp(acModel, acModel.temperature + 0.5);
|
||||
// DevicesCubit.get(context)
|
||||
// .setACTemp(DeviceModel, DeviceModel.temperature + 0.5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsPlus,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_mode_control_unit.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_temp_widget.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/universal_ac_temp.dart';
|
||||
@ -9,8 +9,6 @@ import 'package:syncrow_app/features/devices/view/widgets/universal_switch.dart'
|
||||
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
|
||||
import '../../../model/ac_model.dart';
|
||||
|
||||
class ACsList extends StatelessWidget {
|
||||
const ACsList({
|
||||
super.key,
|
||||
@ -29,7 +27,7 @@ class ACsList extends StatelessWidget {
|
||||
const BodySmall(text: "All ACs"),
|
||||
const SizedBox(height: 5),
|
||||
UniversalSwitch(
|
||||
category: AcCubit.category,
|
||||
category: DevicesCubit.get(context).chosenCategory!,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const UniversalACTemp(),
|
||||
@ -40,9 +38,12 @@ class ACsList extends StatelessWidget {
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
itemCount: AcCubit.category.devices.length,
|
||||
itemCount:
|
||||
DevicesCubit.get(context).chosenCategory!.devices!.length,
|
||||
itemBuilder: (context, index) {
|
||||
ACModel ac = AcCubit.category.devices[index] as ACModel;
|
||||
DeviceModel ac = DevicesCubit.get(context)
|
||||
.chosenCategory!
|
||||
.devices![index] as DeviceModel;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -51,7 +52,11 @@ class ACsList extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
BodySmall(
|
||||
text: AcCubit.category.devices[index].name ?? ""),
|
||||
text: DevicesCubit.get(context)
|
||||
.chosenCategory!
|
||||
.devices![index]
|
||||
.name ??
|
||||
""),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
DevicesCubit.get(context).selectDevice(ac);
|
||||
@ -70,7 +75,6 @@ class ACsList extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
if (AcCubit.category.devices[index] is ACModel)
|
||||
DevicesDefaultSwitch(
|
||||
model: ac,
|
||||
),
|
||||
@ -79,7 +83,6 @@ class ACsList extends StatelessWidget {
|
||||
ac,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (AcCubit.category.devices[index] is ACModel)
|
||||
ACModeControlUnit(
|
||||
model: ac,
|
||||
),
|
||||
|
@ -1,9 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_list.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
|
||||
@ -18,15 +17,16 @@ class ACsView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => AcCubit(),
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<AcCubit, AcState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
ACModel? selectedAC;
|
||||
if (DevicesCubit.get(context).getSelectedDevice() is ACModel) {
|
||||
selectedAC =
|
||||
DevicesCubit.get(context).getSelectedDevice() as ACModel;
|
||||
DeviceModel? selectedAC;
|
||||
if (DevicesCubit.get(context).getSelectedDevice()
|
||||
is DeviceModel) {
|
||||
selectedAC = DevicesCubit.get(context).getSelectedDevice()
|
||||
as DeviceModel;
|
||||
}
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
@ -59,7 +59,7 @@ class ACsView extends StatelessWidget {
|
||||
),
|
||||
child: SizedBox.expand(
|
||||
child: selectedAC != null
|
||||
? AcInterface(acModel: selectedAC)
|
||||
? AcInterface(deviceModel: selectedAC)
|
||||
: const ACsList(),
|
||||
),
|
||||
),
|
||||
|
@ -20,7 +20,7 @@ class CategoryViewAppBar extends StatelessWidget
|
||||
toolbarHeight: Constants.appBarHeight,
|
||||
centerTitle: true,
|
||||
title: DisplayMedium(
|
||||
text: DevicesCubit.get(context).chosenCategory!.name,
|
||||
text: DevicesCubit.get(context).chosenCategory!.name!,
|
||||
style: context.displayMedium.copyWith(
|
||||
color: ColorsManager.primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/AC/ac_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
|
||||
import '../../../../../generated/assets.dart';
|
||||
@ -16,7 +16,7 @@ class UniversalACTemp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AcCubit, AcState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
height: 60,
|
||||
@ -27,8 +27,8 @@ class UniversalACTemp extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context)
|
||||
.setTempToAll(AcCubit.universalACTemp - .5);
|
||||
// DevicesCubit.get(context)
|
||||
// .setTempToAll(DevicesCubit.universalACTemp - .5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsMinus,
|
||||
@ -36,7 +36,8 @@ class UniversalACTemp extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
text: "${AcCubit.universalACTemp}° C",
|
||||
// text: "${DevicesCubit.universalACTemp}° C",
|
||||
text: '25 °C',
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontSize: 23,
|
||||
@ -46,8 +47,8 @@ class UniversalACTemp extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
AcCubit.get(context)
|
||||
.setTempToAll(AcCubit.universalACTemp + .5);
|
||||
// DevicesCubit.get(context)
|
||||
// .setTempToAll(DevicesCubit.universalACTemp + .5);
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.iconsPlus,
|
||||
|
@ -1,8 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/curtains/curtains_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/curtain_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/universal_switch.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
@ -26,7 +25,7 @@ class CurtainList extends StatelessWidget {
|
||||
const BodySmall(text: "All Curtains"),
|
||||
const SizedBox(height: 5),
|
||||
UniversalSwitch(
|
||||
category: CurtainsCubit.category,
|
||||
category: DevicesCubit.get(context).chosenCategory!,
|
||||
),
|
||||
|
||||
// other ACs controls
|
||||
@ -34,19 +33,22 @@ class CurtainList extends StatelessWidget {
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
itemCount: CurtainsCubit.category.devices.length,
|
||||
itemCount:
|
||||
DevicesCubit.get(context).chosenCategory!.devices!.length,
|
||||
itemBuilder: (context, index) {
|
||||
CurtainModel curtain =
|
||||
CurtainsCubit.category.devices[index] as CurtainModel;
|
||||
DeviceModel curtain =
|
||||
DevicesCubit.get(context).chosenCategory!.devices![index];
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
BodySmall(
|
||||
text:
|
||||
CurtainsCubit.category.devices[index].name ?? ""),
|
||||
text: DevicesCubit.get(context)
|
||||
.chosenCategory!
|
||||
.devices![index]
|
||||
.name ??
|
||||
""),
|
||||
const SizedBox(height: 5),
|
||||
if (CurtainsCubit.category.devices[index] is CurtainModel)
|
||||
DevicesDefaultSwitch(
|
||||
model: curtain,
|
||||
),
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/curtains/curtains_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/curtains/curtain_list.dart';
|
||||
@ -15,10 +14,8 @@ class CurtainView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => CurtainsCubit(),
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<CurtainsCubit, CurtainsState>(
|
||||
builder: (context, state) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
@ -56,8 +53,6 @@ class CurtainView extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,29 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/lights/lights_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
import '../../../model/light_model.dart';
|
||||
|
||||
class LightBrightness extends StatelessWidget {
|
||||
const LightBrightness({
|
||||
super.key,
|
||||
required this.light,
|
||||
});
|
||||
|
||||
final LightModel light;
|
||||
final DeviceModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<LightsCubit, LightsState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return GestureDetector(
|
||||
onHorizontalDragUpdate: (details) => LightsCubit.get(context)
|
||||
.onHorizontalDragUpdate(light, details.localPosition.dx,
|
||||
MediaQuery.of(context).size.width - 15),
|
||||
// onHorizontalDragUpdate: (details) => DevicesCubit().get(context)
|
||||
// .onHorizontalDragUpdate(light, details.localPosition.dx,
|
||||
// MediaQuery.of(context).size.width - 15),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
@ -36,22 +35,24 @@ class LightBrightness extends StatelessWidget {
|
||||
duration: const Duration(milliseconds: 0),
|
||||
child: Container(
|
||||
height: 60,
|
||||
width: (MediaQuery.of(context).size.width - 30) *
|
||||
light.brightness /
|
||||
100,
|
||||
// width: (MediaQuery.of(context).size.width - 30) *
|
||||
// light.brightness /
|
||||
// 100,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
borderRadius: light.brightness != 100
|
||||
? const BorderRadius.only(
|
||||
borderRadius:
|
||||
// light.brightness != 100 ?
|
||||
const BorderRadius.only(
|
||||
topLeft: Radius.circular(20),
|
||||
bottomLeft: Radius.circular(20),
|
||||
)
|
||||
: BorderRadius.circular(20),
|
||||
// : BorderRadius.circular(20),
|
||||
),
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
text: "${light.brightness}%",
|
||||
// text: "${light.brightness}%",
|
||||
text: '100%',
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: Colors.black,
|
||||
fontSize: 23,
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/lights/lights_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface_contols.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface_switch.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface_timer.dart';
|
||||
@ -9,11 +9,11 @@ import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface
|
||||
class LightInterface extends StatelessWidget {
|
||||
const LightInterface({super.key, required this.light});
|
||||
|
||||
final LightModel light;
|
||||
final DeviceModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<LightsCubit, LightsState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 70, right: 20, left: 20),
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface_modes.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface_recent_color.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface_slider.dart';
|
||||
@ -11,7 +11,7 @@ class LightInterfaceContols extends StatelessWidget {
|
||||
required this.light,
|
||||
});
|
||||
|
||||
final LightModel light;
|
||||
final DeviceModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/lights/lights_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@ -12,7 +12,7 @@ class LightInterfaceModes extends StatelessWidget {
|
||||
required this.light,
|
||||
});
|
||||
|
||||
final LightModel light;
|
||||
final DeviceModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -27,10 +27,10 @@ class LightInterfaceModes extends StatelessWidget {
|
||||
Wrap(
|
||||
spacing: 25,
|
||||
children: List.generate(
|
||||
LightsCubit.get(context).lightModes.length,
|
||||
DevicesCubit.get(context).lightModes.length,
|
||||
(index) => InkWell(
|
||||
onTap: () => LightsCubit.get(context).setLightingMode(
|
||||
light, LightsCubit.get(context).lightModes[index]!),
|
||||
// onTap: () => DevicesCubit.get(context).setLightingMode(
|
||||
// light, DevicesCubit.get(context).lightModes[index]!),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
|
@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/lights/lights_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
@ -15,7 +14,7 @@ class LightInterfaceRecentColor extends StatelessWidget {
|
||||
required this.light,
|
||||
});
|
||||
|
||||
final LightModel light;
|
||||
final DeviceModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -31,19 +30,20 @@ class LightInterfaceRecentColor extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
...List.generate(
|
||||
light.recentColors.length > 4 ? 4 : light.recentColors.length,
|
||||
// light.recentColors.length > 4 ? 4 : light.recentColors.length,
|
||||
4,
|
||||
(index) => InkWell(
|
||||
onTap: () {
|
||||
LightsCubit.get(context)
|
||||
.setColor(light, light.recentColors[index]);
|
||||
},
|
||||
// onTap: () {
|
||||
// DevicesCubit.get(context)
|
||||
// .setColor(light, light.recentColors[index]);
|
||||
// },
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(right: 10),
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: ShapeDecoration(
|
||||
shape: const CircleBorder(),
|
||||
color: Color(light.recentColors[index]),
|
||||
// color: Color(light.recentColors[index]),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/lights/lights_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/united_text.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
@ -13,7 +12,7 @@ class LightInterfaceSlider extends StatelessWidget {
|
||||
required this.light,
|
||||
});
|
||||
|
||||
final LightModel light;
|
||||
final DeviceModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -29,7 +28,8 @@ class LightInterfaceSlider extends StatelessWidget {
|
||||
children: [
|
||||
Expanded(
|
||||
child: UnitedText(
|
||||
value: light.brightness.toString(),
|
||||
// value: light.brightness.toString(),
|
||||
value: '100',
|
||||
unit: "%",
|
||||
valueStyle: context.bodyMedium.copyWith(
|
||||
color: Colors.grey,
|
||||
@ -57,9 +57,11 @@ class LightInterfaceSlider extends StatelessWidget {
|
||||
trackHeight: 5,
|
||||
),
|
||||
child: Slider(
|
||||
value: light.brightness,
|
||||
onChanged: (value) =>
|
||||
LightsCubit.get(context).setBrightness(light, value),
|
||||
// value: light.brightness,
|
||||
value: 100,
|
||||
onChanged: (value) {
|
||||
// DevicesCubit.get(context).setBrightness(light, value);
|
||||
},
|
||||
min: 0,
|
||||
max: 100,
|
||||
),
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/lights/lights_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/light_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@ -14,7 +13,7 @@ class LightInterfaceSwitch extends StatelessWidget {
|
||||
required this.light,
|
||||
});
|
||||
|
||||
final LightModel light;
|
||||
final DeviceModel light;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -52,7 +51,7 @@ class LightInterfaceSwitch extends StatelessWidget {
|
||||
iconSize: MaterialStateProperty.all(25),
|
||||
),
|
||||
onPressed: () {
|
||||
LightsCubit.get(context).toggleLight(light);
|
||||
// DevicesCubit.get(context).toggleLight(light);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.power_settings_new,
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_brightness.dart';
|
||||
|
||||
import '../../../../shared_widgets/devices_default_switch.dart';
|
||||
import '../../../../shared_widgets/text_widgets/body_small.dart';
|
||||
import '../../../model/light_model.dart';
|
||||
|
||||
class LightsList extends StatelessWidget {
|
||||
const LightsList({
|
||||
@ -12,7 +12,7 @@ class LightsList extends StatelessWidget {
|
||||
required this.lights,
|
||||
});
|
||||
|
||||
final List<LightModel> lights;
|
||||
final List<DeviceModel> lights;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -1,15 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/category_view_app_bar.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_view_list.dart';
|
||||
|
||||
import '../../../../../generated/assets.dart';
|
||||
import '../../../../../utils/resource_manager/color_manager.dart';
|
||||
import '../../../bloc/devices_cubit.dart';
|
||||
import '../../../bloc/lights/lights_cubit.dart';
|
||||
import '../../../model/light_model.dart';
|
||||
import 'light_interface.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class LightsView extends StatelessWidget {
|
||||
const LightsView({super.key});
|
||||
@ -17,19 +15,20 @@ class LightsView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => LightsCubit(),
|
||||
create: (context) => DevicesCubit(),
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<LightsCubit, LightsState>(
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
LightModel? selectedLight;
|
||||
if (DevicesCubit.get(context).getSelectedDevice() is LightModel) {
|
||||
selectedLight =
|
||||
DevicesCubit.get(context).getSelectedDevice() as LightModel;
|
||||
DeviceModel? selectedLight;
|
||||
if (DevicesCubit.get(context).getSelectedDevice()
|
||||
is DeviceModel) {
|
||||
selectedLight = DevicesCubit.get(context).getSelectedDevice()
|
||||
as DeviceModel;
|
||||
}
|
||||
List<LightModel> lights = [];
|
||||
for (var device in DevicesCubit.allCategories[1].devices) {
|
||||
if (device is LightModel) {
|
||||
List<DeviceModel> lights = [];
|
||||
if (DevicesCubit.allCategories[1].devices != null) {
|
||||
for (var device in DevicesCubit.allCategories[1].devices!) {
|
||||
lights.add(device);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/lights_list.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
import '../../../../shared_widgets/text_widgets/body_small.dart';
|
||||
import '../../../bloc/devices_cubit.dart';
|
||||
import '../../../model/light_model.dart';
|
||||
import '../universal_switch.dart';
|
||||
|
||||
class LightsViewList extends StatelessWidget {
|
||||
@ -13,7 +13,7 @@ class LightsViewList extends StatelessWidget {
|
||||
required this.lights,
|
||||
});
|
||||
|
||||
final List<LightModel> lights;
|
||||
final List<DeviceModel> lights;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart';
|
||||
@ -38,7 +37,7 @@ class RoomPageSwitch extends StatelessWidget {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomPageRoute(
|
||||
builder: (context) => AcInterface(acModel: device as ACModel),
|
||||
builder: (context) => AcInterface(deviceModel: device),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ class WizartSwitches extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
DevicesCubit.allCategories[index].icon,
|
||||
DevicesCubit.allCategories[index].icon!,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
CustomSwitch(
|
||||
@ -63,7 +63,7 @@ class WizartSwitches extends StatelessWidget {
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: BodyLarge(
|
||||
text: DevicesCubit.allCategories[index].name,
|
||||
text: DevicesCubit.allCategories[index].name!,
|
||||
style: context.bodyLarge.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 0,
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||
import 'package:syncrow_app/services/api/http_service.dart';
|
||||
@ -15,4 +16,20 @@ class DevicesAPI {
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future<List<DevicesCategoryModel>> fetchGroups(int spaceId) async {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.control,
|
||||
queryParameters: {'homeId': spaceId, 'pageSize': 100, 'page': 1},
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<DevicesCategoryModel> categories = [];
|
||||
for (var category in json['groups']) {
|
||||
categories.add(DevicesCategoryModel.fromJson(category));
|
||||
}
|
||||
},
|
||||
);
|
||||
print('fetchGroups response: $response');
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,10 @@ abstract class Constants {
|
||||
enum DeviceType {
|
||||
AC,
|
||||
Lights,
|
||||
Door,
|
||||
DoorLock,
|
||||
Curtain,
|
||||
ThreeGang,
|
||||
Gateway,
|
||||
Sensors,
|
||||
Other,
|
||||
}
|
||||
|
Reference in New Issue
Block a user