mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-14 17:25:47 +00:00
Implemented Ac functionality, and bug fixes
This commit is contained in:
105
.vscode/launch.json
vendored
105
.vscode/launch.json
vendored
@ -1,60 +1,61 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
// {
|
||||
// "name": "Iphone 15 Pro Max",
|
||||
// "request": "launch",
|
||||
// "type": "dart",
|
||||
// "deviceId": "0147FC23-3D6C-406A-BE2C-9E67BAF3DA9B"
|
||||
// },
|
||||
// {
|
||||
// "name": "Faris Iphone ",
|
||||
// "request": "launch",
|
||||
// "type": "dart",
|
||||
// "deviceId": "00008101-00050C1C02FA001E"
|
||||
// },
|
||||
// {
|
||||
// "name": "Iphone 15 Pro",
|
||||
// "request": "launch",
|
||||
// "type": "dart",
|
||||
// "deviceId": "B26AF31B-D38E-4485-9628-528E0DB29789"
|
||||
// },
|
||||
// {
|
||||
// "name": "Iphone SE",
|
||||
// "request": "launch",
|
||||
// "type": "dart",
|
||||
// "deviceId": "A0274205-52D6-48CC-8344-AB4AE3082DE4",
|
||||
{
|
||||
|
||||
"name": "DEVELOPMENT",
|
||||
|
||||
// },
|
||||
{
|
||||
"name": "syncrow-app",
|
||||
"request": "launch",
|
||||
"type": "dart"
|
||||
},
|
||||
{
|
||||
"name": "syncrow-app (profile mode)",
|
||||
"request": "launch",
|
||||
|
||||
"type": "dart",
|
||||
"flutterMode": "profile"
|
||||
},
|
||||
{
|
||||
"name": "syncrow-app (release mode)",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "release"
|
||||
}
|
||||
|
||||
"args": [
|
||||
|
||||
"--dart-define",
|
||||
|
||||
"FLAVOR=development"
|
||||
|
||||
],
|
||||
// "compounds": [
|
||||
// {
|
||||
// "name": "All Device",
|
||||
// "configurations": [
|
||||
// "Iphone 15 Pro Max",
|
||||
// "Iphone SE"
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
|
||||
"flutterMode": "debug"
|
||||
|
||||
},{
|
||||
|
||||
"name": "STAGING",
|
||||
|
||||
"request": "launch",
|
||||
|
||||
"type": "dart",
|
||||
|
||||
"args": [
|
||||
|
||||
"--dart-define",
|
||||
|
||||
"FLAVOR=staging"
|
||||
|
||||
],
|
||||
|
||||
"flutterMode": "debug"
|
||||
|
||||
},{
|
||||
|
||||
"name": "PRODUCTION",
|
||||
|
||||
"request": "launch",
|
||||
|
||||
"type": "dart",
|
||||
|
||||
"args": [
|
||||
|
||||
"--dart-define",
|
||||
|
||||
"FLAVOR=production"
|
||||
|
||||
],
|
||||
|
||||
"flutterMode": "debug"
|
||||
|
||||
},
|
||||
|
||||
]
|
||||
}
|
@ -153,7 +153,7 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
emitSafe(GetSpaceRoomsError(failure.toString()));
|
||||
return;
|
||||
}
|
||||
if (space.rooms != null) {
|
||||
if (space.rooms != null && space.rooms!.isNotEmpty) {
|
||||
emitSafe(GetSpaceRoomsSuccess(space.rooms!));
|
||||
} else {
|
||||
emitSafe(GetSpaceRoomsError("No rooms found"));
|
||||
|
128
lib/features/devices/bloc/acs_bloc/acs_bloc.dart
Normal file
128
lib/features/devices/bloc/acs_bloc/acs_bloc.dart
Normal file
@ -0,0 +1,128 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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/status_model.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
final String acId;
|
||||
late DeviceModel deviceModel;
|
||||
|
||||
ACsBloc({required this.acId}) : super(AcsInitialState()) {
|
||||
on<AcsInitial>(_fetchAcsStatus);
|
||||
on<IncreaseCoolToTemp>(_increaseCoolTo);
|
||||
on<DecreaseCoolToTemp>(_decreaseCoolTo);
|
||||
on<SetCurrentTemp>(_setCurrentTemperature);
|
||||
on<ChangeAcMode>(_changeAcMode);
|
||||
on<ChangeFanSpeed>(_changeFanSpeed);
|
||||
}
|
||||
|
||||
void _fetchAcsStatus(AcsInitial event, Emitter<AcsState> emit) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
var response = await DevicesAPI.getDeviceStatus(acId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
AcStatusModel deviceStatus = AcStatusModel.fromJson(statusModelList);
|
||||
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void _setCurrentTemperature(SetCurrentTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
int value = (event.value * 10).toInt();
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_current', value: value), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
// emit(AcIncreaseCoolTo(tempValue: tempValue));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
// emit(AcIncreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
}
|
||||
|
||||
void _increaseCoolTo(IncreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
|
||||
double tempValue = event.value + 0.5;
|
||||
int value = (tempValue * 10).toInt();
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(AcIncreaseCoolTo(tempValue: tempValue));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
emit(AcIncreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
}
|
||||
|
||||
void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
|
||||
double tempValue = event.value - 0.5;
|
||||
int value = (tempValue * 10).toInt();
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(AcDecreaseCoolTo(tempValue: tempValue));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
emit(AcDecreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
}
|
||||
|
||||
void _changeAcMode(ChangeAcMode event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
|
||||
final tempMode = tempModesMap[getNextItem(tempModesMap, event.tempModes)]!;
|
||||
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'mode', value: getACModeString(tempMode)), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(AcModeState(tempModes: tempMode));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
// emit(AcDecreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
}
|
||||
|
||||
void _changeFanSpeed(ChangeFanSpeed event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
|
||||
final fanSpeed = event.fanSpeeds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'level', value: getNextFanSpeedKey(fanSpeed)),
|
||||
acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(FanSpeedState(fanSpeeds: fanSpeed));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
// emit(AcDecreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
}
|
||||
|
||||
String getACModeString(TempModes value) {
|
||||
if (value == TempModes.cold) {
|
||||
return 'cold';
|
||||
} else if (value == TempModes.hot) {
|
||||
return 'hot';
|
||||
} else if (value == TempModes.wind) {
|
||||
return 'wind';
|
||||
} else {
|
||||
return 'cold';
|
||||
}
|
||||
}
|
||||
}
|
55
lib/features/devices/bloc/acs_bloc/acs_events.dart
Normal file
55
lib/features/devices/bloc/acs_bloc/acs_events.dart
Normal file
@ -0,0 +1,55 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
abstract class AcsEvent extends Equatable {
|
||||
const AcsEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AcsLoading extends AcsEvent {}
|
||||
|
||||
class AcsInitial extends AcsEvent {}
|
||||
|
||||
class ACsChangeStatus extends AcsEvent {}
|
||||
|
||||
class IncreaseCoolToTemp extends AcsEvent {
|
||||
final double value;
|
||||
const IncreaseCoolToTemp({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class DecreaseCoolToTemp extends AcsEvent {
|
||||
final double value;
|
||||
const DecreaseCoolToTemp({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class SetCurrentTemp extends AcsEvent {
|
||||
final double value;
|
||||
const SetCurrentTemp({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class ChangeAcMode extends AcsEvent {
|
||||
final TempModes tempModes;
|
||||
const ChangeAcMode({required this.tempModes});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempModes];
|
||||
}
|
||||
|
||||
class ChangeFanSpeed extends AcsEvent {
|
||||
final FanSpeeds fanSpeeds;
|
||||
const ChangeFanSpeed({required this.fanSpeeds});
|
||||
|
||||
@override
|
||||
List<Object> get props => [fanSpeeds];
|
||||
}
|
72
lib/features/devices/bloc/acs_bloc/acs_state.dart
Normal file
72
lib/features/devices/bloc/acs_bloc/acs_state.dart
Normal file
@ -0,0 +1,72 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
abstract class AcsState extends Equatable {
|
||||
const AcsState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class AcsInitialState extends AcsState {}
|
||||
|
||||
class AcsLoadingState extends AcsState {}
|
||||
|
||||
class AcChangeTempLoading extends AcsState {}
|
||||
|
||||
class AcChangeCurrentTempState extends AcsState {
|
||||
final double currentValue;
|
||||
const AcChangeCurrentTempState({required this.currentValue});
|
||||
|
||||
@override
|
||||
List<Object> get props => [currentValue];
|
||||
}
|
||||
|
||||
class AcIncreaseCoolTo extends AcsState {
|
||||
final double tempValue;
|
||||
const AcIncreaseCoolTo({required this.tempValue});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempValue];
|
||||
}
|
||||
|
||||
class AcDecreaseCoolTo extends AcsState {
|
||||
final double tempValue;
|
||||
const AcDecreaseCoolTo({required this.tempValue});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempValue];
|
||||
}
|
||||
|
||||
class GetAcStatusState extends AcsState {
|
||||
final AcStatusModel acStatusModel;
|
||||
const GetAcStatusState({required this.acStatusModel});
|
||||
|
||||
@override
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class AcModeState extends AcsState {
|
||||
final TempModes tempModes;
|
||||
const AcModeState({required this.tempModes});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempModes];
|
||||
}
|
||||
|
||||
class FanSpeedState extends AcsState {
|
||||
final FanSpeeds fanSpeeds;
|
||||
const FanSpeedState({required this.fanSpeeds});
|
||||
|
||||
@override
|
||||
List<Object> get props => [fanSpeeds];
|
||||
}
|
||||
|
||||
class AcsFailedState extends AcsState {
|
||||
final String error;
|
||||
const AcsFailedState({required this.error});
|
||||
|
||||
@override
|
||||
List<Object> get props => [error];
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
// import 'package:bloc/bloc.dart';
|
||||
// import 'package:flutter/foundation.dart';
|
||||
// import 'package:meta/meta.dart';
|
||||
// import 'package:syncrow_app/features/devices/bloc/devices_cubit.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());
|
||||
// DeviceModel? getSelectedAC() {
|
||||
// DevicesCategoryModel category = DevicesCubit.allCategories![0];
|
||||
// for (var device in category.devices) {
|
||||
// if (device is && device.isSelected) {
|
||||
// return device;
|
||||
// }
|
||||
// }
|
||||
// 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
|
||||
// }
|
||||
|
||||
// }
|
@ -1,6 +0,0 @@
|
||||
// part of 'ac_cubit.dart';
|
||||
|
||||
// @immutable
|
||||
// sealed class AcState {}
|
||||
|
||||
// final class AcInitial extends AcState {}
|
@ -19,7 +19,6 @@ import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||
import 'package:syncrow_app/services/api/spaces_api.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
part 'devices_state.dart';
|
||||
|
||||
class DevicesCubit extends Cubit<DevicesState> {
|
||||
@ -37,8 +36,6 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
return _instance ??= DevicesCubit._();
|
||||
}
|
||||
|
||||
DeviceModel? selectedDevice;
|
||||
|
||||
@override
|
||||
Future<void> close() {
|
||||
_instance = null;
|
||||
@ -100,14 +97,14 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
DevicesCategoryModel? get chosenCategory {
|
||||
for (var category in allCategories!) {
|
||||
if (category.isSelected) {
|
||||
return category;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// DevicesCategoryModel? get chosenCategory {
|
||||
// for (var category in allCategories!) {
|
||||
// if (category.isSelected) {
|
||||
// return category;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
selectDevice(DeviceModel device) {
|
||||
for (var category in allCategories!) {
|
||||
@ -251,7 +248,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
code: control.code,
|
||||
));
|
||||
try {
|
||||
var response = await DevicesAPI.controlDevice(control);
|
||||
var response = await DevicesAPI.controlDevice(control, deviceId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emitSafe(DeviceControlSuccess(code: control.code));
|
||||
@ -306,12 +303,12 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
//get status for each device
|
||||
//TODO get devices status per page via page controller instead of getting all devices status at once
|
||||
List<DeviceModel> devices = HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!;
|
||||
if (devices.isNotEmpty) {
|
||||
for (var device in devices) {
|
||||
fetchDevicesStatues(device.uuid!, roomIndex);
|
||||
}
|
||||
}
|
||||
// List<DeviceModel> devices = HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!;
|
||||
// if (devices.isNotEmpty) {
|
||||
// for (var device in devices) {
|
||||
// fetchDevicesStatues(device.uuid!, roomIndex);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
fetchDevicesStatues(String deviceUuid, int roomIndex, {String? code}) async {
|
||||
|
@ -19,7 +19,7 @@ class DeviceControlModel {
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'deviceUuid': deviceId,
|
||||
// 'deviceUuid': deviceId,
|
||||
'code': code,
|
||||
'value': value,
|
||||
};
|
||||
|
@ -1,3 +1,84 @@
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class AcStatusModel {
|
||||
bool acSwitch;
|
||||
String modeString;
|
||||
int tempSet;
|
||||
int currentTemp;
|
||||
String fanSpeedsString;
|
||||
bool childLock;
|
||||
late TempModes acMode;
|
||||
late FanSpeeds acFanSpeed;
|
||||
|
||||
AcStatusModel(
|
||||
{required this.acSwitch,
|
||||
required this.modeString,
|
||||
required this.tempSet,
|
||||
required this.currentTemp,
|
||||
required this.fanSpeedsString,
|
||||
required this.childLock}) {
|
||||
acMode = getACMode(modeString);
|
||||
acFanSpeed = getFanSpeed(fanSpeedsString);
|
||||
}
|
||||
|
||||
factory AcStatusModel.fromJson(List<StatusModel> jsonList) {
|
||||
late bool _acSwitch;
|
||||
late String _mode;
|
||||
late int _tempSet;
|
||||
late int _currentTemp;
|
||||
late String _fanSpeeds;
|
||||
late bool _childLock;
|
||||
for (int i = 0; i < jsonList.length; i++) {
|
||||
if (jsonList[i].code == 'switch') {
|
||||
_acSwitch = jsonList[i].value ?? false;
|
||||
} else if (jsonList[i].code == 'mode') {
|
||||
_mode = jsonList[i].value ?? TempModes.cold;
|
||||
} else if (jsonList[i].code == 'temp_set') {
|
||||
_tempSet = jsonList[i].value ?? 210;
|
||||
} else if (jsonList[i].code == 'temp_current') {
|
||||
_currentTemp = jsonList[i].value ?? 210;
|
||||
} else if (jsonList[i].code == 'level') {
|
||||
_fanSpeeds = jsonList[i].value ?? 210;
|
||||
} else if (jsonList[i].code == 'child_lock') {
|
||||
_childLock = jsonList[i].value ?? false;
|
||||
}
|
||||
}
|
||||
return AcStatusModel(
|
||||
acSwitch: _acSwitch,
|
||||
modeString: _mode,
|
||||
tempSet: _tempSet,
|
||||
currentTemp: _currentTemp,
|
||||
fanSpeedsString: _fanSpeeds,
|
||||
childLock: _childLock);
|
||||
}
|
||||
|
||||
TempModes getACMode(String value) {
|
||||
if (value == 'cold') {
|
||||
return TempModes.cold;
|
||||
} else if (value == 'hot') {
|
||||
return TempModes.hot;
|
||||
} else if (value == 'wind') {
|
||||
return TempModes.wind;
|
||||
} else {
|
||||
return TempModes.cold;
|
||||
}
|
||||
}
|
||||
|
||||
FanSpeeds getFanSpeed(String value) {
|
||||
if (value == 'low') {
|
||||
return FanSpeeds.low;
|
||||
} else if (value == 'middle') {
|
||||
return FanSpeeds.middle;
|
||||
} else if (value == 'high') {
|
||||
return FanSpeeds.high;
|
||||
} else if (value == 'auto') {
|
||||
return FanSpeeds.auto;
|
||||
} else {
|
||||
return FanSpeeds.auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StatusModel {
|
||||
String? code;
|
||||
dynamic value;
|
||||
|
@ -1,6 +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/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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_interface_controls.dart';
|
||||
@ -18,37 +20,24 @@ class AcInterface extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
),
|
||||
child: SafeArea(
|
||||
child: BlocConsumer<DevicesCubit, DevicesState>(
|
||||
return BlocConsumer<ACsBloc, AcsState>(
|
||||
listener: (context, state) {
|
||||
if (state is DeviceControlError) {
|
||||
// ScaffoldMessenger.of(context).showSnackBar(
|
||||
// SnackBar(
|
||||
// content: Text(state.errorMsg),
|
||||
// ),
|
||||
// );
|
||||
if (state is AcsFailedState) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.error),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: BodyLarge(
|
||||
text: ac.name ?? "",
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
fontWeight: FontsManager.bold,
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
return
|
||||
// Scaffold(
|
||||
// backgroundColor: ColorsManager.backgroundColor,
|
||||
// extendBodyBehindAppBar: true,
|
||||
// extendBody: true,
|
||||
// body:
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
@ -93,11 +82,9 @@ class AcInterface extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
// );
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
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/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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';
|
||||
@ -17,7 +19,7 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
return Column(
|
||||
children: [
|
||||
@ -31,8 +33,7 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child:
|
||||
SvgPicture.asset(Assets.assetsIconsAutomatedClock),
|
||||
child: SvgPicture.asset(Assets.assetsIconsAutomatedClock),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -2,8 +2,10 @@ 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/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.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/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
@ -23,12 +25,9 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
double setToTemp = acDevice.status
|
||||
.firstWhere((element) => element.code == 'temp_set')
|
||||
.value /
|
||||
10;
|
||||
// double setToTemp = 250;
|
||||
return DefaultContainer(
|
||||
child: Column(
|
||||
children: [
|
||||
@ -44,13 +43,11 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
shadowWidth: 0,
|
||||
),
|
||||
customColors: CustomSliderColors(
|
||||
progressBarColor:
|
||||
ColorsManager.primaryColor.withOpacity(.6),
|
||||
progressBarColor: ColorsManager.primaryColor.withOpacity(.6),
|
||||
trackColor: ColorsManager.greyColor,
|
||||
dotColor: Colors.transparent,
|
||||
),
|
||||
infoProperties: InfoProperties(
|
||||
//TODO: move to strings manager
|
||||
bottomLabelText: 'CURRENT TEMP',
|
||||
bottomLabelStyle: context.bodyLarge.copyWith(
|
||||
color: Colors.grey,
|
||||
@ -79,23 +76,19 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
// max: DeviceModel.bounds.max,
|
||||
min: 20,
|
||||
max: 30,
|
||||
initialValue: acDevice.status
|
||||
.firstWhere(
|
||||
(element) => element.code == 'temp_current')
|
||||
.value /
|
||||
10,
|
||||
onChange: (value) {
|
||||
String valueAsString = value.toStringAsFixed(1);
|
||||
if (valueAsString.endsWith(".0") ||
|
||||
valueAsString.endsWith(".5")) {
|
||||
value = double.parse(valueAsString);
|
||||
DevicesCubit.getInstance().deviceControl(
|
||||
DeviceControlModel(
|
||||
deviceId: acDevice.uuid,
|
||||
code: 'temp_set',
|
||||
value: value * 10),
|
||||
acDevice.uuid!);
|
||||
}
|
||||
initialValue:
|
||||
state is GetAcStatusState ? state.acStatusModel.currentTemp / 10 : 25,
|
||||
onChange: (value) async {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
// String valueAsString = value.toStringAsFixed(1);
|
||||
// if (valueAsString.endsWith(".0") || valueAsString.endsWith(".5")) {
|
||||
// value = double.parse(valueAsString);
|
||||
BlocProvider.of<ACsBloc>(context).add(SetCurrentTemp(value: value));
|
||||
// await DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid, code: 'temp_set', value: value * 10),
|
||||
// acDevice.uuid!);
|
||||
// }
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -109,23 +102,37 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
//TODO refactor the loading check
|
||||
if (state is GetDeviceStatusLoading &&
|
||||
state.code == 'temp_set' ||
|
||||
state is DeviceControlSuccess &&
|
||||
state.code == 'temp_set' ||
|
||||
state is DeviceControlLoading &&
|
||||
state.code == 'temp_set') {
|
||||
if (state is AcChangeTempLoading) {
|
||||
return;
|
||||
}
|
||||
if (setToTemp > 20) {
|
||||
DevicesCubit.getInstance().deviceControl(
|
||||
DeviceControlModel(
|
||||
deviceId: acDevice.uuid,
|
||||
code: 'temp_set',
|
||||
value: (setToTemp - 0.5) * 10),
|
||||
acDevice.uuid!);
|
||||
|
||||
double tempValue = 0;
|
||||
if (state is AcIncreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
} else if (state is GetAcStatusState) {
|
||||
tempValue = state.acStatusModel.tempSet / 10;
|
||||
} else if (state is AcDecreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
}
|
||||
|
||||
if (tempValue > 20) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(DecreaseCoolToTemp(value: tempValue));
|
||||
}
|
||||
//TODO refactor the loading check
|
||||
// if (state is AcsLoadingState ||
|
||||
// state is DeviceControlSuccess ||
|
||||
// state is DeviceControlLoading) {
|
||||
// return;
|
||||
// }
|
||||
// if (setToTemp > 20) {
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'temp_set',
|
||||
// value: (setToTemp - 0.5) * 10),
|
||||
// acDevice.uuid!);
|
||||
// }
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsMinus,
|
||||
@ -136,14 +143,15 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
children: [
|
||||
BodyLarge(
|
||||
// text: "${DeviceModel.coolTo}° C",
|
||||
text: '$setToTemp° C',
|
||||
text: state is AcIncreaseCoolTo
|
||||
? '${state.tempValue}° C'
|
||||
: state is AcDecreaseCoolTo
|
||||
? '${state.tempValue}° C'
|
||||
: state is GetAcStatusState
|
||||
? '${state.acStatusModel.tempSet / 10}° C'
|
||||
: '',
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: state is GetDeviceStatusLoading &&
|
||||
state.code == 'temp_set' ||
|
||||
state is DeviceControlSuccess &&
|
||||
state.code == 'temp_set' ||
|
||||
state is DeviceControlLoading &&
|
||||
state.code == 'temp_set'
|
||||
color: state is AcsLoadingState
|
||||
? Colors.grey
|
||||
: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontWeight: FontsManager.bold,
|
||||
@ -160,22 +168,36 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (state is GetDeviceStatusLoading &&
|
||||
state.code == 'temp_set' ||
|
||||
state is DeviceControlSuccess &&
|
||||
state.code == 'temp_set' ||
|
||||
state is DeviceControlLoading &&
|
||||
state.code == 'temp_set') {
|
||||
if (state is AcChangeTempLoading) {
|
||||
return;
|
||||
}
|
||||
if (setToTemp < 30) {
|
||||
DevicesCubit.getInstance().deviceControl(
|
||||
DeviceControlModel(
|
||||
deviceId: acDevice.uuid,
|
||||
code: 'temp_set',
|
||||
value: (setToTemp + 0.5) * 10),
|
||||
acDevice.uuid!);
|
||||
|
||||
double tempValue = 0;
|
||||
if (state is AcIncreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
} else if (state is GetAcStatusState) {
|
||||
tempValue = state.acStatusModel.tempSet / 10;
|
||||
} else if (state is AcDecreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
}
|
||||
|
||||
if (tempValue < 30) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(IncreaseCoolToTemp(value: tempValue));
|
||||
}
|
||||
// if (state is GetDeviceStatusLoading ||
|
||||
// state is DeviceControlSuccess ||
|
||||
// state is DeviceControlLoading) {
|
||||
// return;
|
||||
// }
|
||||
// if (setToTemp < 30) {
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'temp_set',
|
||||
// value: (setToTemp + 0.5) * 10),
|
||||
// acDevice.uuid!);
|
||||
// }
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsPlus,
|
||||
|
@ -1,13 +1,16 @@
|
||||
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/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.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/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class ACModeControlUnit extends StatefulWidget {
|
||||
class ACModeControlUnit extends StatelessWidget {
|
||||
const ACModeControlUnit({
|
||||
super.key,
|
||||
required this.acDevice,
|
||||
@ -15,21 +18,12 @@ class ACModeControlUnit extends StatefulWidget {
|
||||
|
||||
final DeviceModel acDevice;
|
||||
|
||||
@override
|
||||
State<ACModeControlUnit> createState() => _ACModeControlUnitState();
|
||||
}
|
||||
|
||||
class _ACModeControlUnitState extends State<ACModeControlUnit> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
FanSpeeds fanSpeed = fanSpeedsMap[widget.acDevice.status
|
||||
.firstWhere((element) => element.code == 'level')
|
||||
.value]!;
|
||||
TempModes tempMode = tempModesMap[widget.acDevice.status
|
||||
.firstWhere((element) => element.code == 'mode')
|
||||
.value]!;
|
||||
// FanSpeeds fanSpeed = FanSpeeds.middle;
|
||||
// TempModes tempMode = TempModes.cold;
|
||||
return Row(
|
||||
children: [
|
||||
Flexible(
|
||||
@ -37,27 +31,29 @@ class _ACModeControlUnitState extends State<ACModeControlUnit> {
|
||||
onTap: () {
|
||||
// print(
|
||||
// '\n\ncurrentFanSpeed:$fanSpeed \nchanged to:\t${fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!}\nKey:\t\t\"${reversedFanSpeedsMap[fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!]!}\"');
|
||||
if (state is GetAcStatusState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
|
||||
} else if (state is FanSpeedState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.fanSpeeds));
|
||||
}
|
||||
|
||||
fanSpeed = fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!;
|
||||
|
||||
DevicesCubit.getInstance().deviceControl(
|
||||
DeviceControlModel(
|
||||
deviceId: widget.acDevice.uuid,
|
||||
code: 'level',
|
||||
value: reversedFanSpeedsMap[fanSpeed]!),
|
||||
widget.acDevice.uuid!);
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'level',
|
||||
// value: reversedFanSpeedsMap[fanSpeed]!),
|
||||
// acDevice.uuid!);
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: state is GetDeviceStatusLoading &&
|
||||
state.code == 'level' ||
|
||||
state is DeviceControlSuccess &&
|
||||
state.code == 'level' ||
|
||||
state is DeviceControlLoading &&
|
||||
state.code == 'level'
|
||||
? const CircularProgressIndicator()
|
||||
: SvgPicture.asset(fanSpeedsIconMap[fanSpeed]!)),
|
||||
child: state is GetAcStatusState
|
||||
? SvgPicture.asset(fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
|
||||
: state is FanSpeedState
|
||||
? SvgPicture.asset(fanSpeedsIconMap[state.fanSpeeds]!)
|
||||
: const CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -65,25 +61,29 @@ class _ACModeControlUnitState extends State<ACModeControlUnit> {
|
||||
Flexible(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
tempMode = tempModesMap[getNextItem(tempModesMap, tempMode)]!;
|
||||
DevicesCubit.getInstance().deviceControl(
|
||||
DeviceControlModel(
|
||||
deviceId: widget.acDevice.uuid,
|
||||
code: 'mode',
|
||||
value: reversedTempModesMap[tempMode]!),
|
||||
widget.acDevice.uuid!);
|
||||
if (state is GetAcStatusState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
|
||||
} else if (state is FanSpeedState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.fanSpeeds));
|
||||
}
|
||||
// tempMode = tempModesMap[getNextItem(tempModesMap, tempMode)]!;
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'mode',
|
||||
// value: reversedTempModesMap[tempMode]!),
|
||||
// acDevice.uuid!);
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: state is GetDeviceStatusLoading &&
|
||||
state.code == 'mode' ||
|
||||
state is DeviceControlSuccess &&
|
||||
state.code == 'mode' ||
|
||||
state is DeviceControlLoading &&
|
||||
state.code == 'mode'
|
||||
? const CircularProgressIndicator()
|
||||
: SvgPicture.asset(tempModesIconMap[tempMode]!),
|
||||
child: state is GetAcStatusState
|
||||
? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
|
||||
: state is AcModeState
|
||||
? SvgPicture.asset(tempModesIconMap[state.tempModes]!)
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -1,6 +1,8 @@
|
||||
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/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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';
|
||||
@ -20,7 +22,7 @@ class ACTempWidget extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
height: 60,
|
||||
|
@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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';
|
||||
@ -16,7 +18,7 @@ class ACsList extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
@ -26,9 +28,9 @@ class ACsList extends StatelessWidget {
|
||||
const SizedBox(height: 10),
|
||||
const BodySmall(text: "All ACs"),
|
||||
const SizedBox(height: 5),
|
||||
UniversalSwitch(
|
||||
category: DevicesCubit.getInstance().chosenCategory!,
|
||||
),
|
||||
// UniversalSwitch(
|
||||
// category: DevicesCubit.getInstance().chosenCategory!,
|
||||
// ),
|
||||
const SizedBox(height: 10),
|
||||
const UniversalACTemp(),
|
||||
const SizedBox(height: 10),
|
||||
@ -38,12 +40,9 @@ class ACsList extends StatelessWidget {
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
itemCount:
|
||||
DevicesCubit.getInstance().chosenCategory!.devices!.length,
|
||||
// itemCount: DevicesCubit.getInstance().chosenCategory!.devices!.length,
|
||||
itemBuilder: (context, index) {
|
||||
DeviceModel ac = DevicesCubit.getInstance()
|
||||
.chosenCategory!
|
||||
.devices![index];
|
||||
// DeviceModel ac = DevicesCubit.getInstance().chosenCategory!.devices![index];
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@ -51,15 +50,13 @@ class ACsList extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
BodySmall(
|
||||
text: DevicesCubit.getInstance()
|
||||
.chosenCategory!
|
||||
.devices![index]
|
||||
.name ??
|
||||
""),
|
||||
// BodySmall(
|
||||
// text:
|
||||
// DevicesCubit.getInstance().chosenCategory!.devices![index].name ??
|
||||
// ""),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
DevicesCubit.getInstance().selectDevice(ac);
|
||||
// DevicesCubit.getInstance().selectDevice(ac);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
@ -75,17 +72,17 @@ class ACsList extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(
|
||||
model: ac,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ACTempWidget(
|
||||
ac,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ACModeControlUnit(
|
||||
acDevice: ac,
|
||||
),
|
||||
// DevicesDefaultSwitch(
|
||||
// model: ac,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// ACTempWidget(
|
||||
// ac,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// ACModeControlUnit(
|
||||
// acDevice: ac,
|
||||
// ),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
|
@ -1,29 +1,33 @@
|
||||
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/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
|
||||
class ACsView extends StatelessWidget {
|
||||
const ACsView({super.key});
|
||||
final DeviceModel? deviceModel;
|
||||
const ACsView({this.deviceModel, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocProvider(
|
||||
create: (context) => ACsBloc(acId: deviceModel?.uuid ?? '')..add(AcsInitial()),
|
||||
child: BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
DeviceModel? selectedAC;
|
||||
if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
|
||||
selectedAC =
|
||||
DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
||||
}
|
||||
// BlocProvider.of<ACsBloc>(context).add(AcsInitial());
|
||||
// DeviceModel? selectedAC;
|
||||
// if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
|
||||
// selectedAC = DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
||||
// }
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
@ -34,7 +38,9 @@ class ACsView extends StatelessWidget {
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: const CategoryViewAppBar(),
|
||||
appBar: CategoryViewAppBar(
|
||||
title: deviceModel?.name ?? '',
|
||||
),
|
||||
body: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
@ -53,10 +59,13 @@ class ACsView extends StatelessWidget {
|
||||
left: Constants.defaultPadding,
|
||||
right: Constants.defaultPadding,
|
||||
),
|
||||
child: SizedBox.expand(
|
||||
child: selectedAC != null
|
||||
? AcInterface(ac: selectedAC)
|
||||
: const ACsList(),
|
||||
child: state is AcsLoadingState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
: SizedBox.expand(
|
||||
child: deviceModel != null ? AcInterface(ac: deviceModel!) : ACsList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -64,8 +73,7 @@ class ACsView extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -5,9 +5,10 @@ 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/constants.dart';
|
||||
|
||||
class CategoryViewAppBar extends StatelessWidget
|
||||
implements PreferredSizeWidget {
|
||||
class CategoryViewAppBar extends StatelessWidget implements PreferredSizeWidget {
|
||||
final String title;
|
||||
const CategoryViewAppBar({
|
||||
required this.title,
|
||||
super.key,
|
||||
});
|
||||
|
||||
@ -19,11 +20,10 @@ class CategoryViewAppBar extends StatelessWidget
|
||||
toolbarHeight: Constants.appBarHeight,
|
||||
centerTitle: true,
|
||||
title: DisplayMedium(
|
||||
text: DevicesCubit.getInstance().chosenCategory!.name!,
|
||||
style: context.displayMedium.copyWith(
|
||||
color: ColorsManager.primaryColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
// text: DevicesCubit.getInstance().chosenCategory!.name!,
|
||||
text: title,
|
||||
style: context.displayMedium
|
||||
.copyWith(color: ColorsManager.primaryColor, fontWeight: FontWeight.bold, fontSize: 14),
|
||||
),
|
||||
leading: IconButton(
|
||||
icon: const Icon(
|
||||
@ -31,7 +31,8 @@ class CategoryViewAppBar extends StatelessWidget
|
||||
color: ColorsManager.textPrimaryColor,
|
||||
),
|
||||
onPressed: () {
|
||||
DevicesCubit.getInstance().clearCategoriesSelection(context);
|
||||
Navigator.of(context).pop();
|
||||
// DevicesCubit.getInstance().clearCategoriesSelection(context);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
@ -1,6 +1,8 @@
|
||||
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/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
@ -15,7 +17,7 @@ class UniversalACTemp extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
return DefaultContainer(
|
||||
height: 60,
|
||||
|
@ -24,34 +24,34 @@ class CurtainList extends StatelessWidget {
|
||||
//TODO: move to strings manager
|
||||
const BodySmall(text: "All Curtains"),
|
||||
const SizedBox(height: 5),
|
||||
UniversalSwitch(
|
||||
category: DevicesCubit.get(context).chosenCategory!,
|
||||
),
|
||||
// UniversalSwitch(
|
||||
// category: DevicesCubit.get(context).chosenCategory!,
|
||||
// ),
|
||||
|
||||
// other ACs controls
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
itemCount:
|
||||
DevicesCubit.get(context).chosenCategory!.devices!.length,
|
||||
// itemCount:
|
||||
// DevicesCubit.get(context).chosenCategory!.devices!.length,
|
||||
itemBuilder: (context, index) {
|
||||
DeviceModel curtain =
|
||||
DevicesCubit.get(context).chosenCategory!.devices![index];
|
||||
// DeviceModel curtain =
|
||||
// DevicesCubit.get(context).chosenCategory!.devices![index];
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 20),
|
||||
BodySmall(
|
||||
text: DevicesCubit.get(context)
|
||||
.chosenCategory!
|
||||
.devices![index]
|
||||
.name ??
|
||||
""),
|
||||
// BodySmall(
|
||||
// text: DevicesCubit.get(context)
|
||||
// .chosenCategory!
|
||||
// .devices![index]
|
||||
// .name ??
|
||||
// ""),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(
|
||||
model: curtain,
|
||||
),
|
||||
// DevicesDefaultSwitch(
|
||||
// model: curtain,
|
||||
// ),
|
||||
],
|
||||
);
|
||||
},
|
||||
|
@ -13,7 +13,9 @@ class CurtainListView extends StatelessWidget {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return const DefaultScaffold(
|
||||
appBar: CategoryViewAppBar(),
|
||||
appBar: CategoryViewAppBar(
|
||||
title: '',
|
||||
),
|
||||
child: CurtainList(),
|
||||
);
|
||||
},
|
||||
|
@ -38,7 +38,9 @@ class LightsView extends StatelessWidget {
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: const CategoryViewAppBar(),
|
||||
appBar: const CategoryViewAppBar(
|
||||
title: '',
|
||||
),
|
||||
body: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
|
@ -2,20 +2,15 @@
|
||||
///
|
||||
/// This widget displays the icon and name of the device, along with a switch
|
||||
/// to control its state. Tapping on the widget opens the device interface.
|
||||
library;
|
||||
|
||||
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/devices_cubit.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_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/wall_sensor_interface.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/ceiling_sensor_interface.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_interface.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart';
|
||||
@ -87,14 +82,13 @@ class RoomPageSwitch extends StatelessWidget {
|
||||
void showDeviceInterface(DeviceModel device, BuildContext context) {
|
||||
switch (device.productType) {
|
||||
case DeviceType.AC:
|
||||
navigateToInterface(AcInterface(ac: device), context);
|
||||
navigateToInterface(ACsView(deviceModel: device), context);
|
||||
break;
|
||||
case DeviceType.WallSensor:
|
||||
navigateToInterface(WallMountedInterface(wallSensor: device), context);
|
||||
break;
|
||||
case DeviceType.CeilingSensor:
|
||||
navigateToInterface(
|
||||
CeilingSensorInterface(ceilingSensor: device), context);
|
||||
navigateToInterface(CeilingSensorInterface(ceilingSensor: device), context);
|
||||
break;
|
||||
case DeviceType.Curtain:
|
||||
break;
|
||||
|
@ -9,8 +9,7 @@ abstract class ApiEndpoints {
|
||||
static const String deleteUser = '$baseUrl/authentication/user/delete/{id}';
|
||||
static const String sendOtp = '$baseUrl/authentication/user/send-otp';
|
||||
static const String verifyOtp = '$baseUrl/authentication/user/verify-otp';
|
||||
static const String forgetPassword =
|
||||
'$baseUrl/authentication/user/forget-password';
|
||||
static const String forgetPassword = '$baseUrl/authentication/user/forget-password';
|
||||
|
||||
////////////////////////////////////// Spaces ///////////////////////////////////////
|
||||
|
||||
@ -20,12 +19,10 @@ abstract class ApiEndpoints {
|
||||
static const String addCommunityToUser = '$baseUrl/community/user';
|
||||
//GET
|
||||
static const String communityByUuid = '$baseUrl/community/{communityUuid}';
|
||||
static const String communityChild =
|
||||
'$baseUrl/community/child/{communityUuid}';
|
||||
static const String communityChild = '$baseUrl/community/child/{communityUuid}';
|
||||
static const String communityUser = '$baseUrl/community/user/{userUuid}';
|
||||
//PUT
|
||||
static const String renameCommunity =
|
||||
'$baseUrl/community/rename/{communityUuid}';
|
||||
static const String renameCommunity = '$baseUrl/community/rename/{communityUuid}';
|
||||
|
||||
///Building Module
|
||||
//POST
|
||||
@ -34,12 +31,10 @@ abstract class ApiEndpoints {
|
||||
//GET
|
||||
static const String buildingByUuid = '$baseUrl/building/{buildingUuid}';
|
||||
static const String buildingChild = '$baseUrl/building/child/{buildingUuid}';
|
||||
static const String buildingParent =
|
||||
'$baseUrl/building/parent/{buildingUuid}';
|
||||
static const String buildingParent = '$baseUrl/building/parent/{buildingUuid}';
|
||||
static const String buildingUser = '$baseUrl/building/user/{userUuid}';
|
||||
//PUT
|
||||
static const String renameBuilding =
|
||||
'$baseUrl/building/rename/{buildingUuid}';
|
||||
static const String renameBuilding = '$baseUrl/building/rename/{buildingUuid}';
|
||||
|
||||
///Floor Module
|
||||
//POST
|
||||
@ -91,14 +86,12 @@ abstract class ApiEndpoints {
|
||||
//POST
|
||||
static const String addDeviceToRoom = '$baseUrl/device/room';
|
||||
static const String addDeviceToGroup = '$baseUrl/device/group';
|
||||
static const String controlDevice = '$baseUrl/device/control';
|
||||
static const String controlDevice = '$baseUrl/device/{deviceUuid}/control';
|
||||
//GET
|
||||
static const String deviceByRoom = '$baseUrl/device/room';
|
||||
static const String deviceByUuid = '$baseUrl/device/{deviceUuid}';
|
||||
static const String deviceFunctions =
|
||||
'$baseUrl/device/{deviceUuid}/functions';
|
||||
static const String deviceFunctionsStatus =
|
||||
'$baseUrl/device/{deviceUuid}/functions/status';
|
||||
static const String deviceFunctions = '$baseUrl/device/{deviceUuid}/functions';
|
||||
static const String deviceFunctionsStatus = '$baseUrl/device/{deviceUuid}/functions/status';
|
||||
|
||||
///Device Permission Module
|
||||
//POST
|
||||
@ -106,6 +99,5 @@ abstract class ApiEndpoints {
|
||||
//GET
|
||||
static const String devicePermissionList = '$baseUrl/device-permission/list';
|
||||
//PUT
|
||||
static const String editDevicePermission =
|
||||
'$baseUrl/device-permission/edit/{userId}';
|
||||
static const String editDevicePermission = '$baseUrl/device-permission/edit/{userId}';
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ class DevicesAPI {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
static Future<Map<String, dynamic>> controlDevice(
|
||||
DeviceControlModel controlModel) async {
|
||||
DeviceControlModel controlModel, String deviceId) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.controlDevice,
|
||||
path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', deviceId),
|
||||
body: controlModel.toJson(),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
@ -27,26 +27,20 @@ class DevicesAPI {
|
||||
}
|
||||
|
||||
static Future<List<DevicesCategoryModel>> fetchGroups(String spaceId) async {
|
||||
Map<String, dynamic> params = {
|
||||
"homeId": spaceId,
|
||||
"pageSize": 100,
|
||||
"pageNo": 1
|
||||
};
|
||||
Map<String, dynamic> params = {"homeId": spaceId, "pageSize": 100, "pageNo": 1};
|
||||
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.groupBySpace.replaceAll("{spaceUuid}", spaceId),
|
||||
queryParameters: params,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) =>
|
||||
DevicesCategoryModel.fromJsonList(json['groups']),
|
||||
expectedResponseModel: (json) => DevicesCategoryModel.fromJsonList(json['groups']),
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.deviceFunctionsStatus
|
||||
.replaceAll('{deviceUuid}', deviceId),
|
||||
path: ApiEndpoints.deviceFunctionsStatus.replaceAll('{deviceUuid}', deviceId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
|
@ -122,7 +122,7 @@ packages:
|
||||
source: hosted
|
||||
version: "5.4.1"
|
||||
equatable:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: equatable
|
||||
sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2
|
||||
|
@ -37,6 +37,7 @@ dependencies:
|
||||
firebase_crashlytics: ^3.4.16
|
||||
smooth_page_indicator: ^1.1.0
|
||||
html: ^0.15.4
|
||||
equatable: ^2.0.5
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Reference in New Issue
Block a user