mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
Implemented devices groups
This commit is contained in:
5
assets/icons/ac_switch_ic.svg
Normal file
5
assets/icons/ac_switch_ic.svg
Normal file
@ -0,0 +1,5 @@
|
||||
<svg width="35" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="17.5" cy="17.5" r="17.5" fill="#023DFE" fill-opacity="0.6"/>
|
||||
<path d="M19.6872 11.5562C19.6895 11.7012 19.7342 11.8424 19.8157 11.9624C19.8971 12.0823 20.0119 12.1758 20.1459 12.2314C21.3433 12.7583 22.356 13.6311 23.0538 14.7376C23.7516 15.8442 24.1028 17.1341 24.0622 18.4417C24.034 20.1822 23.3155 21.8402 22.0648 23.0509C20.8142 24.2617 19.1338 24.926 17.3933 24.8978C15.6528 24.8695 13.9948 24.1511 12.7841 22.9004C11.5733 21.6497 10.909 19.9693 10.9372 18.2288C10.9389 16.9573 11.3099 15.7137 12.0052 14.6491C12.7005 13.5845 13.69 12.7448 14.8536 12.2321C14.9876 12.1762 15.1024 12.0824 15.1839 11.9622C15.2653 11.842 15.3099 11.7007 15.3122 11.5555C15.3124 11.4361 15.2833 11.3184 15.2273 11.2129C15.1714 11.1073 15.0904 11.0172 14.9915 10.9503C14.8925 10.8834 14.7787 10.8418 14.6599 10.8292C14.5412 10.8166 14.4211 10.8334 14.3104 10.8781C12.6182 11.6117 11.2305 12.9061 10.3811 14.5433C9.53177 16.1805 9.27256 18.0603 9.6472 19.8663C10.0218 21.6722 11.0074 23.2938 12.4379 24.4581C13.8684 25.6223 15.6564 26.2579 17.5008 26.2579C19.3452 26.2579 21.1332 25.6223 22.5637 24.4581C23.9943 23.2938 24.9798 21.6722 25.3545 19.8663C25.7291 18.0603 25.4699 16.1805 24.6205 14.5433C23.7711 12.9061 22.3835 11.6117 20.6913 10.8781C20.5804 10.8329 20.46 10.8158 20.3409 10.8282C20.2218 10.8406 20.1075 10.8822 20.0083 10.9492C19.909 11.0162 19.8278 11.1067 19.7718 11.2125C19.7158 11.3184 19.6868 11.4364 19.6872 11.5562Z" fill="white"/>
|
||||
<path d="M18.2291 9.47917C18.2291 9.07646 17.9026 8.75 17.4999 8.75C17.0972 8.75 16.7708 9.07646 16.7708 9.47917V13.8542C16.7708 14.2569 17.0972 14.5833 17.4999 14.5833C17.9026 14.5833 18.2291 14.2569 18.2291 13.8542V9.47917Z" fill="white"/>
|
||||
</svg>
|
After Width: | Height: | Size: 1.8 KiB |
@ -281,4 +281,4 @@ SPEC CHECKSUMS:
|
||||
|
||||
PODFILE CHECKSUM: cf86fcba3fb3dbd505936bc190bb0b8fe3dd2498
|
||||
|
||||
COCOAPODS: 1.13.0
|
||||
COCOAPODS: 1.15.2
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
@ -10,21 +11,46 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
final String acId;
|
||||
late DeviceModel deviceModel;
|
||||
late AcStatusModel deviceStatus;
|
||||
AcStatusModel deviceStatus = AcStatusModel(
|
||||
acSwitch: true,
|
||||
modeString: 'hot',
|
||||
tempSet: 300,
|
||||
currentTemp: 315,
|
||||
fanSpeedsString: 'low',
|
||||
childLock: false);
|
||||
List<AcStatusModel> deviceStatusList = [];
|
||||
List<DeviceModel> devicesList = [];
|
||||
bool allAcsPage = false;
|
||||
bool allAcsOn = true;
|
||||
bool allTempSame = true;
|
||||
int globalTemp = 25;
|
||||
|
||||
ACsBloc({required this.acId}) : super(AcsInitialState()) {
|
||||
on<AcsInitial>(_fetchAcsStatus);
|
||||
on<AcSwitch>(_changeAcSwitch);
|
||||
on<IncreaseCoolToTemp>(_increaseCoolTo);
|
||||
on<DecreaseCoolToTemp>(_decreaseCoolTo);
|
||||
on<ChangeLock>(_changeLockValue);
|
||||
on<ChangeAcMode>(_changeAcMode);
|
||||
on<ChangeFanSpeed>(_changeFanSpeed);
|
||||
on<ChangeAllSwitch>(_changeAllAcSwitch);
|
||||
on<IncreaseAllTemp>(_increaseAllTemp);
|
||||
on<DecreaseAllTemp>(_decreaseAllTemp);
|
||||
}
|
||||
|
||||
void _fetchAcsStatus(AcsInitial event, Emitter<AcsState> emit) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
allAcsPage = event.allAcs;
|
||||
if (event.allAcs) {
|
||||
await _getAllAcs();
|
||||
emit(GetAllAcsStatusState(
|
||||
allAcsStatues: deviceStatusList,
|
||||
allAcs: devicesList,
|
||||
allOn: allAcsOn,
|
||||
allTempSame: allTempSame,
|
||||
temp: globalTemp));
|
||||
} else {
|
||||
var response = await DevicesAPI.getDeviceStatus(acId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
@ -32,12 +58,118 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
}
|
||||
deviceStatus = AcStatusModel.fromJson(statusModelList);
|
||||
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_getAllAcs() async {
|
||||
deviceStatusList = [];
|
||||
devicesList = [];
|
||||
allAcsOn = true;
|
||||
allTempSame = true;
|
||||
devicesList = await DevicesAPI.getDeviceByGroupName(
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', 'AC');
|
||||
|
||||
for (int i = 0; i < devicesList.length; i++) {
|
||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatusList.add(AcStatusModel.fromJson(statusModelList));
|
||||
}
|
||||
if (deviceStatusList.isNotEmpty) {
|
||||
int temp = deviceStatusList[0].tempSet;
|
||||
deviceStatusList.firstWhere((element) {
|
||||
if (!element.acSwitch) {
|
||||
allAcsOn = false;
|
||||
}
|
||||
if (element.tempSet != temp) {
|
||||
allTempSame = false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
if (allTempSame) {
|
||||
globalTemp = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _changeAcSwitch(AcSwitch event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
|
||||
final acSwitchValue = !event.acSwitch;
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: allAcsPage ? event.deviceId : acId, code: 'switch', value: acSwitchValue),
|
||||
allAcsPage ? event.deviceId : acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.acSwitch = acSwitchValue;
|
||||
}
|
||||
} catch (_) {}
|
||||
if (allAcsPage) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
} else {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
void _changeAllAcSwitch(ChangeAllSwitch event, Emitter<AcsState> emit) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
if (deviceStatusList.length == devicesList.length) {
|
||||
for (int i = 0; i < deviceStatusList.length; i++) {
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: devicesList[i].uuid, code: 'switch', value: event.value),
|
||||
devicesList[i].uuid ?? '');
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
}
|
||||
|
||||
void _increaseAllTemp(IncreaseAllTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
double tempValue = event.value + 0.5;
|
||||
int value = (tempValue * 10).toInt();
|
||||
if (deviceStatusList.length == devicesList.length) {
|
||||
for (int i = 0; i < deviceStatusList.length; i++) {
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: devicesList[i].uuid, code: 'temp_set', value: value),
|
||||
devicesList[i].uuid ?? '');
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
}
|
||||
|
||||
void _decreaseAllTemp(DecreaseAllTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcsLoadingState());
|
||||
try {
|
||||
double tempValue = event.value - 0.5;
|
||||
int value = (tempValue * 10).toInt();
|
||||
if (deviceStatusList.length == devicesList.length) {
|
||||
for (int i = 0; i < deviceStatusList.length; i++) {
|
||||
await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: devicesList[i].uuid, code: 'temp_set', value: value),
|
||||
devicesList[i].uuid ?? '');
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
}
|
||||
|
||||
void _changeLockValue(ChangeLock event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
|
||||
@ -59,14 +191,21 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
int value = (tempValue * 10).toInt();
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
DeviceControlModel(
|
||||
deviceId: allAcsPage ? event.deviceId : acId, code: 'temp_set', value: value),
|
||||
allAcsPage ? event.deviceId : acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.tempSet = value;
|
||||
}
|
||||
} catch (_) {}
|
||||
if (allAcsPage) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
} else {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
@ -75,37 +214,56 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
int value = (tempValue * 10).toInt();
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
DeviceControlModel(
|
||||
deviceId: allAcsPage ? event.deviceId : acId, code: 'temp_set', value: value),
|
||||
allAcsPage ? event.deviceId : acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.tempSet = value;
|
||||
}
|
||||
} catch (_) {}
|
||||
if (allAcsPage) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
} else {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
void _changeAcMode(ChangeAcMode event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
final tempMode = tempModesMap[getNextItem(tempModesMap, event.tempModes)]!;
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'mode', value: getACModeString(tempMode)), acId);
|
||||
DeviceControlModel(
|
||||
deviceId: allAcsPage ? event.deviceId : acId,
|
||||
code: 'mode',
|
||||
value: getACModeString(tempMode)),
|
||||
allAcsPage ? event.deviceId : acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.modeString = getACModeString(tempMode);
|
||||
deviceStatus.acMode = AcStatusModel.getACMode(getACModeString(tempMode));
|
||||
}
|
||||
} catch (_) {}
|
||||
if (allAcsPage) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
} else {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
void _changeFanSpeed(ChangeFanSpeed event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
|
||||
final fanSpeed = event.fanSpeeds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'level', value: getNextFanSpeedKey(fanSpeed)),
|
||||
acId);
|
||||
DeviceControlModel(
|
||||
deviceId: allAcsPage ? event.deviceId : acId,
|
||||
code: 'level',
|
||||
value: getNextFanSpeedKey(fanSpeed)),
|
||||
allAcsPage ? event.deviceId : acId);
|
||||
|
||||
try {
|
||||
if (response['success'] ?? false) {
|
||||
@ -113,8 +271,13 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||
}
|
||||
} catch (_) {}
|
||||
if (allAcsPage) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const AcsInitial(allAcs: true));
|
||||
} else {
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
String getACModeString(TempModes value) {
|
||||
if (value == TempModes.cold) {
|
||||
|
@ -10,40 +10,58 @@ abstract class AcsEvent extends Equatable {
|
||||
|
||||
class AcsLoading extends AcsEvent {}
|
||||
|
||||
class AcsInitial extends AcsEvent {}
|
||||
class AcSwitch extends AcsEvent {
|
||||
final bool acSwitch;
|
||||
final String deviceId;
|
||||
const AcSwitch({required this.acSwitch, this.deviceId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [acSwitch, deviceId];
|
||||
}
|
||||
|
||||
class AcsInitial extends AcsEvent {
|
||||
final bool allAcs;
|
||||
const AcsInitial({required this.allAcs});
|
||||
@override
|
||||
List<Object> get props => [allAcs];
|
||||
}
|
||||
|
||||
class ACsChangeStatus extends AcsEvent {}
|
||||
|
||||
class IncreaseCoolToTemp extends AcsEvent {
|
||||
final double value;
|
||||
const IncreaseCoolToTemp({required this.value});
|
||||
final String deviceId;
|
||||
const IncreaseCoolToTemp({required this.value, this.deviceId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
List<Object> get props => [value, deviceId];
|
||||
}
|
||||
|
||||
class DecreaseCoolToTemp extends AcsEvent {
|
||||
final double value;
|
||||
const DecreaseCoolToTemp({required this.value});
|
||||
final String deviceId;
|
||||
const DecreaseCoolToTemp({required this.value, this.deviceId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
List<Object> get props => [value, deviceId];
|
||||
}
|
||||
|
||||
class ChangeAcMode extends AcsEvent {
|
||||
final TempModes tempModes;
|
||||
const ChangeAcMode({required this.tempModes});
|
||||
final String deviceId;
|
||||
const ChangeAcMode({required this.tempModes, this.deviceId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempModes];
|
||||
List<Object> get props => [tempModes, deviceId];
|
||||
}
|
||||
|
||||
class ChangeFanSpeed extends AcsEvent {
|
||||
final FanSpeeds fanSpeeds;
|
||||
const ChangeFanSpeed({required this.fanSpeeds});
|
||||
final String deviceId;
|
||||
const ChangeFanSpeed({required this.fanSpeeds, this.deviceId = ''});
|
||||
|
||||
@override
|
||||
List<Object> get props => [fanSpeeds];
|
||||
List<Object> get props => [fanSpeeds, deviceId];
|
||||
}
|
||||
|
||||
class ChangeLock extends AcsEvent {
|
||||
@ -53,3 +71,27 @@ class ChangeLock extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [lockBool];
|
||||
}
|
||||
|
||||
class ChangeAllSwitch extends AcsEvent {
|
||||
final bool value;
|
||||
const ChangeAllSwitch({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class IncreaseAllTemp extends AcsEvent {
|
||||
final double value;
|
||||
const IncreaseAllTemp({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class DecreaseAllTemp extends AcsEvent {
|
||||
final double value;
|
||||
const DecreaseAllTemp({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
|
||||
abstract class AcsState extends Equatable {
|
||||
const AcsState();
|
||||
@ -36,6 +37,24 @@ class GetAcStatusState extends AcsState {
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class GetAllAcsStatusState extends AcsState {
|
||||
final List<AcStatusModel> allAcsStatues;
|
||||
final List<DeviceModel> allAcs;
|
||||
final bool allOn;
|
||||
final bool allTempSame;
|
||||
final int temp;
|
||||
|
||||
const GetAllAcsStatusState(
|
||||
{required this.allAcsStatues,
|
||||
required this.allAcs,
|
||||
required this.allOn,
|
||||
required this.allTempSame,
|
||||
required this.temp});
|
||||
|
||||
@override
|
||||
List<Object> get props => [allAcsStatues, allAcs, allAcs, allTempSame, temp];
|
||||
}
|
||||
|
||||
class AcsFailedState extends AcsState {
|
||||
final String error;
|
||||
|
||||
|
@ -29,6 +29,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) {
|
||||
fetchDevicesByRoomId(room.id!);
|
||||
}
|
||||
fetchGroups(HomeCubit.getInstance().selectedSpace?.id ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,7 +53,7 @@ class DevicesCubit extends Cubit<DevicesState> {
|
||||
|
||||
static DevicesCubit get(context) => BlocProvider.of(context);
|
||||
|
||||
static List<DevicesCategoryModel>? allCategories;
|
||||
List<DevicesCategoryModel>? allCategories;
|
||||
|
||||
selectCategory(int index) {
|
||||
for (var i = 0; i < allCategories!.length; i++) {
|
||||
|
@ -1,16 +1,29 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_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/group_three_gang_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
|
||||
import 'package:syncrow_app/services/api/devices_api.dart';
|
||||
|
||||
class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
final String threeGangId;
|
||||
late ThreeGangModel deviceStatus;
|
||||
ThreeGangModel deviceStatus = ThreeGangModel(
|
||||
firstSwitch: false,
|
||||
secondSwitch: false,
|
||||
thirdSwitch: false,
|
||||
firstCountDown: 0,
|
||||
secondCountDown: 0,
|
||||
thirdCountDown: 0);
|
||||
Timer? _timer;
|
||||
bool threeGangGroup = false;
|
||||
List<DeviceModel> devicesList = [];
|
||||
List<GroupThreeGangModel> groupThreeGangList = [];
|
||||
bool allSwitchesOn = true;
|
||||
|
||||
ThreeGangBloc({required this.threeGangId}) : super(InitialState()) {
|
||||
on<InitialEvent>(_fetchThreeGangStatus);
|
||||
@ -24,11 +37,47 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
on<GetCounterEvent>(_getCounterValue);
|
||||
on<TickTimer>(_onTickTimer);
|
||||
on<OnClose>(_onClose);
|
||||
on<GroupAllOnEvent>(_groupAllOn);
|
||||
on<GroupAllOffEvent>(_groupAllOff);
|
||||
}
|
||||
|
||||
void _fetchThreeGangStatus(InitialEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingInitialState());
|
||||
try {
|
||||
threeGangGroup = event.groupScreen;
|
||||
if (threeGangGroup) {
|
||||
devicesList = [];
|
||||
groupThreeGangList = [];
|
||||
allSwitchesOn = true;
|
||||
devicesList = await DevicesAPI.getDeviceByGroupName(
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '', '3G');
|
||||
|
||||
for (int i = 0; i < devicesList.length; i++) {
|
||||
var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? '');
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
deviceStatus = ThreeGangModel.fromJson(statusModelList);
|
||||
|
||||
groupThreeGangList.add(GroupThreeGangModel(
|
||||
deviceId: devicesList[i].uuid ?? '',
|
||||
deviceName: devicesList[i].name ?? '',
|
||||
firstSwitch: deviceStatus.firstSwitch,
|
||||
secondSwitch: deviceStatus.secondSwitch,
|
||||
thirdSwitch: deviceStatus.thirdSwitch));
|
||||
}
|
||||
|
||||
if (groupThreeGangList.isNotEmpty) {
|
||||
groupThreeGangList.firstWhere((element) {
|
||||
if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) {
|
||||
allSwitchesOn = false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesOn));
|
||||
} else {
|
||||
var response = await DevicesAPI.getDeviceStatus(threeGangId);
|
||||
List<StatusModel> statusModelList = [];
|
||||
for (var status in response['status']) {
|
||||
@ -36,6 +85,7 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
}
|
||||
deviceStatus = ThreeGangModel.fromJson(statusModelList);
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(FailedState(error: e.toString()));
|
||||
return;
|
||||
@ -46,44 +96,68 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: threeGangId, code: 'switch_1', value: !event.value),
|
||||
threeGangId);
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||
code: 'switch_1',
|
||||
value: !event.value),
|
||||
threeGangGroup ? event.deviceId : threeGangId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.firstSwitch = !event.value;
|
||||
}
|
||||
} catch (_) {}
|
||||
if (threeGangGroup) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
} else {
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
void _changeSecondSwitch(
|
||||
ChangeSecondSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: threeGangId, code: 'switch_2', value: !event.value),
|
||||
threeGangId);
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||
code: 'switch_2',
|
||||
value: !event.value),
|
||||
threeGangGroup ? event.deviceId : threeGangId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.secondSwitch = !event.value;
|
||||
}
|
||||
} catch (_) {}
|
||||
if (threeGangGroup) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
} else {
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: threeGangId, code: 'switch_3', value: !event.value),
|
||||
threeGangId);
|
||||
DeviceControlModel(
|
||||
deviceId: threeGangGroup ? event.deviceId : threeGangId,
|
||||
code: 'switch_3',
|
||||
value: !event.value),
|
||||
threeGangGroup ? event.deviceId : threeGangId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.thirdSwitch = !event.value;
|
||||
}
|
||||
} catch (_) {}
|
||||
if (threeGangGroup) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
} else {
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
}
|
||||
|
||||
void _allOff(AllOffEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
@ -129,6 +203,56 @@ class ThreeGangBloc extends Bloc<ThreeGangEvent, ThreeGangState> {
|
||||
emit(UpdateState(threeGangModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _groupAllOn(GroupAllOnEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
|
||||
try {
|
||||
for (int i = 0; i < groupThreeGangList.length; i++) {
|
||||
await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId, code: 'switch_1', value: true),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId, code: 'switch_2', value: true),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId, code: 'switch_3', value: true),
|
||||
groupThreeGangList[i].deviceId),
|
||||
]);
|
||||
}
|
||||
} catch (_) {}
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
|
||||
void _groupAllOff(GroupAllOffEvent event, Emitter<ThreeGangState> emit) async {
|
||||
emit(LoadingNewSate(threeGangModel: deviceStatus));
|
||||
|
||||
try {
|
||||
for (int i = 0; i < groupThreeGangList.length; i++) {
|
||||
await Future.wait([
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId, code: 'switch_1', value: false),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId, code: 'switch_2', value: false),
|
||||
groupThreeGangList[i].deviceId),
|
||||
DevicesAPI.controlDevice(
|
||||
DeviceControlModel(
|
||||
deviceId: groupThreeGangList[i].deviceId, code: 'switch_3', value: false),
|
||||
groupThreeGangList[i].deviceId),
|
||||
]);
|
||||
}
|
||||
} catch (_) {}
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
add(const InitialEvent(groupScreen: true));
|
||||
}
|
||||
|
||||
void _changeSliding(ChangeSlidingSegment event, Emitter<ThreeGangState> emit) async {
|
||||
emit(ChangeSlidingSegmentState(value: event.value));
|
||||
}
|
||||
|
@ -9,33 +9,45 @@ abstract class ThreeGangEvent extends Equatable {
|
||||
|
||||
class LoadingEvent extends ThreeGangEvent {}
|
||||
|
||||
class InitialEvent extends ThreeGangEvent {}
|
||||
class InitialEvent extends ThreeGangEvent {
|
||||
final bool groupScreen;
|
||||
const InitialEvent({required this.groupScreen});
|
||||
@override
|
||||
List<Object> get props => [groupScreen];
|
||||
}
|
||||
|
||||
class ChangeFirstSwitchStatusEvent extends ThreeGangEvent {
|
||||
final bool value;
|
||||
const ChangeFirstSwitchStatusEvent({required this.value});
|
||||
final String deviceId;
|
||||
const ChangeFirstSwitchStatusEvent({required this.value, this.deviceId = ''});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
List<Object> get props => [value, deviceId];
|
||||
}
|
||||
|
||||
class ChangeSecondSwitchStatusEvent extends ThreeGangEvent {
|
||||
final bool value;
|
||||
const ChangeSecondSwitchStatusEvent({required this.value});
|
||||
final String deviceId;
|
||||
const ChangeSecondSwitchStatusEvent({required this.value, this.deviceId = ''});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
List<Object> get props => [value, deviceId];
|
||||
}
|
||||
|
||||
class ChangeThirdSwitchStatusEvent extends ThreeGangEvent {
|
||||
final bool value;
|
||||
const ChangeThirdSwitchStatusEvent({required this.value});
|
||||
final String deviceId;
|
||||
const ChangeThirdSwitchStatusEvent({required this.value, this.deviceId = ''});
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
List<Object> get props => [value, deviceId];
|
||||
}
|
||||
|
||||
class AllOffEvent extends ThreeGangEvent {}
|
||||
|
||||
class AllOnEvent extends ThreeGangEvent {}
|
||||
|
||||
class GroupAllOnEvent extends ThreeGangEvent {}
|
||||
|
||||
class GroupAllOffEvent extends ThreeGangEvent {}
|
||||
|
||||
class ChangeSlidingSegment extends ThreeGangEvent {
|
||||
final int value;
|
||||
const ChangeSlidingSegment({required this.value});
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/group_three_gang_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
|
||||
|
||||
class ThreeGangState extends Equatable {
|
||||
@ -28,6 +29,16 @@ class LoadingNewSate extends ThreeGangState {
|
||||
List<Object> get props => [threeGangModel];
|
||||
}
|
||||
|
||||
class UpdateGroupState extends ThreeGangState {
|
||||
final List<GroupThreeGangModel> threeGangList;
|
||||
final bool allSwitches;
|
||||
|
||||
const UpdateGroupState({required this.threeGangList, required this.allSwitches});
|
||||
|
||||
@override
|
||||
List<Object> get props => [threeGangList, allSwitches];
|
||||
}
|
||||
|
||||
class FailedState extends ThreeGangState {
|
||||
final String error;
|
||||
|
||||
|
@ -40,11 +40,9 @@ class DevicesCategoryModel {
|
||||
|
||||
DevicesCategoryModel.fromJson(Map<String, dynamic> json)
|
||||
: name = json['groupName'],
|
||||
id = json['groupId'],
|
||||
type = devicesTypesMap[json['productType']] ?? DeviceType.Other,
|
||||
icon = deviceTypeIconMap[
|
||||
devicesTypesMap[json['productType']] ?? DeviceType.Other] ??
|
||||
'',
|
||||
// id = json['groupId'],
|
||||
type = devicesTypesMap[json['groupName']] ?? DeviceType.Other,
|
||||
icon = deviceTypeIconMap[devicesTypesMap[json['groupName']] ?? DeviceType.Other] ?? '',
|
||||
devices = [],
|
||||
isSelected = false;
|
||||
|
||||
|
15
lib/features/devices/model/group_three_gang_model.dart
Normal file
15
lib/features/devices/model/group_three_gang_model.dart
Normal file
@ -0,0 +1,15 @@
|
||||
class GroupThreeGangModel {
|
||||
final String deviceId;
|
||||
final String deviceName;
|
||||
final bool firstSwitch;
|
||||
final bool secondSwitch;
|
||||
final bool thirdSwitch;
|
||||
|
||||
GroupThreeGangModel({
|
||||
required this.deviceId,
|
||||
required this.deviceName,
|
||||
required this.firstSwitch,
|
||||
required this.secondSwitch,
|
||||
required this.thirdSwitch,
|
||||
});
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
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_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
|
||||
class AcInterface extends StatelessWidget {
|
||||
const AcInterface({super.key, required this.ac});
|
||||
@ -24,6 +30,23 @@ class AcInterface extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
builder: (context, state) {
|
||||
AcStatusModel statusModel = AcStatusModel(
|
||||
acSwitch: true,
|
||||
modeString: 'hot',
|
||||
tempSet: 300,
|
||||
currentTemp: 315,
|
||||
fanSpeedsString: 'low',
|
||||
childLock: false);
|
||||
|
||||
if (state is GetAcStatusState) {
|
||||
statusModel = state.acStatusModel;
|
||||
}
|
||||
if (state is AcChangeLoading) {
|
||||
statusModel = state.acStatusModel;
|
||||
}
|
||||
if (state is AcModifyingState) {
|
||||
statusModel = state.acStatusModel;
|
||||
}
|
||||
return
|
||||
// Scaffold(
|
||||
// backgroundColor: ColorsManager.backgroundColor,
|
||||
@ -34,6 +57,28 @@ class AcInterface extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
DefaultContainer(
|
||||
height: 65,
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
BodyLarge(text: statusModel.acSwitch ? 'On' : 'Off'),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(AcSwitch(acSwitch: statusModel.acSwitch));
|
||||
},
|
||||
child: SvgPicture.asset(Assets.acSwitchIcon))
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 380,
|
||||
@ -51,6 +96,7 @@ class AcInterface extends StatelessWidget {
|
||||
),
|
||||
child: AcInterfaceControls(
|
||||
deviceModel: ac,
|
||||
deviceStatus: statusModel,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -4,45 +4,31 @@ 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_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.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';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
|
||||
class AcInterfaceControls extends StatelessWidget {
|
||||
const AcInterfaceControls({
|
||||
super.key,
|
||||
required this.deviceModel,
|
||||
});
|
||||
const AcInterfaceControls({super.key, required this.deviceModel, required this.deviceStatus});
|
||||
|
||||
final DeviceModel deviceModel;
|
||||
final AcStatusModel deviceStatus;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
String lockIconName = Assets.assetsIconsLock;
|
||||
bool lockValue = false;
|
||||
|
||||
if (state is GetAcStatusState) {
|
||||
lockIconName =
|
||||
state.acStatusModel.childLock ? Assets.assetsIconsLock : Assets.assetsIconsUnLock;
|
||||
lockValue = state.acStatusModel.childLock;
|
||||
}
|
||||
if (state is AcChangeLoading) {
|
||||
lockIconName =
|
||||
state.acStatusModel.childLock ? Assets.assetsIconsLock : Assets.assetsIconsUnLock;
|
||||
lockValue = state.acStatusModel.childLock;
|
||||
}
|
||||
if (state is AcModifyingState) {
|
||||
lockIconName =
|
||||
state.acStatusModel.childLock ? Assets.assetsIconsLock : Assets.assetsIconsUnLock;
|
||||
lockValue = state.acStatusModel.childLock;
|
||||
}
|
||||
String lockIconName =
|
||||
deviceStatus.childLock ? Assets.assetsIconsLock : Assets.assetsIconsUnLock;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
ACModeControlUnit(acDevice: deviceModel),
|
||||
ACModeControlUnit(
|
||||
acStatus: deviceStatus,
|
||||
deviceId: deviceModel.uuid ?? '',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
@ -61,7 +47,8 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
Flexible(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
BlocProvider.of<ACsBloc>(context).add(ChangeLock(lockBool: lockValue));
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeLock(lockBool: deviceStatus.childLock));
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
|
@ -4,48 +4,41 @@ 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_event.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/model/ac_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
class ACModeControlUnit extends StatelessWidget {
|
||||
const ACModeControlUnit({
|
||||
super.key,
|
||||
required this.acDevice,
|
||||
required this.acStatus,
|
||||
required this.deviceId,
|
||||
});
|
||||
|
||||
final DeviceModel acDevice;
|
||||
final AcStatusModel acStatus;
|
||||
final String deviceId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
// FanSpeeds fanSpeed = FanSpeeds.middle;
|
||||
// TempModes tempMode = TempModes.cold;
|
||||
return Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (state is GetAcStatusState) {
|
||||
if (state is! AcChangeLoading && state is! AcsLoadingState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
|
||||
} else if (state is AcModifyingState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
|
||||
.add(ChangeFanSpeed(fanSpeeds: acStatus.acFanSpeed, deviceId: deviceId));
|
||||
}
|
||||
// else if (state is AcModifyingState) {
|
||||
// BlocProvider.of<ACsBloc>(context)
|
||||
// .add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
|
||||
// }
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: state is GetAcStatusState
|
||||
? SvgPicture.asset(fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
|
||||
: state is AcModifyingState
|
||||
? SvgPicture.asset(fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
|
||||
: state is AcChangeLoading
|
||||
? SvgPicture.asset(
|
||||
fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
|
||||
: const CircularProgressIndicator()),
|
||||
child: Center(child: SvgPicture.asset(fanSpeedsIconMap[acStatus.acFanSpeed]!)),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -53,24 +46,22 @@ class ACModeControlUnit extends StatelessWidget {
|
||||
Flexible(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (state is GetAcStatusState) {
|
||||
// if (state is GetAcStatusState) {
|
||||
// BlocProvider.of<ACsBloc>(context)
|
||||
// .add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
|
||||
// } else if (state is AcModifyingState) {
|
||||
// BlocProvider.of<ACsBloc>(context)
|
||||
// .add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
|
||||
// }
|
||||
if (state is! AcChangeLoading && state is! AcsLoadingState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
|
||||
} else if (state is AcModifyingState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
|
||||
.add(ChangeAcMode(tempModes: acStatus.acMode, deviceId: deviceId));
|
||||
}
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: state is GetAcStatusState
|
||||
? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
|
||||
: state is AcModifyingState
|
||||
? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
|
||||
: state is AcChangeLoading
|
||||
? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
|
||||
: const CircularProgressIndicator(),
|
||||
child: SvgPicture.asset(tempModesIconMap[acStatus.acMode]!),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -2,6 +2,7 @@ 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_event.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/shared_widgets/default_container.dart';
|
||||
@ -11,12 +12,14 @@ import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
|
||||
class ACTempWidget extends StatelessWidget {
|
||||
const ACTempWidget(
|
||||
this.deviceModel, {
|
||||
const ACTempWidget({
|
||||
required this.deviceModel,
|
||||
required this.temp,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final DeviceModel deviceModel;
|
||||
final int temp;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -31,8 +34,11 @@ class ACTempWidget extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// DevicesCubit.getInstance()
|
||||
// .setACTemp(DeviceModel, DeviceModel.temperature - 0.5);
|
||||
double tempC = temp / 10;
|
||||
if (tempC > 20) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(DecreaseCoolToTemp(value: tempC, deviceId: deviceModel.uuid ?? ''));
|
||||
}
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsMinus,
|
||||
@ -40,8 +46,7 @@ class ACTempWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
// text: "${DeviceModel.temperature}° C",
|
||||
text: '25 °C',
|
||||
text: '${temp / 10} °C',
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontSize: 23,
|
||||
@ -51,8 +56,11 @@ class ACTempWidget extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// DevicesCubit.getInstance()
|
||||
// .setACTemp(DeviceModel, DeviceModel.temperature + 0.5);
|
||||
double tempC = temp / 10;
|
||||
if (tempC < 30) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(IncreaseCoolToTemp(value: tempC, deviceId: deviceModel.uuid ?? ''));
|
||||
}
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsPlus,
|
||||
|
@ -1,13 +1,15 @@
|
||||
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_event.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/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/devices/view/widgets/ACs/ac_temp_widget.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/universal_ac_temp.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/universal_switch.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
|
||||
@ -20,19 +22,39 @@ class ACsList extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
List<AcStatusModel> devicesStatuesList = [];
|
||||
List<DeviceModel> devicesList = [];
|
||||
bool allOn = false;
|
||||
bool allTempSame = false;
|
||||
int temperature = 20;
|
||||
if (state is GetAllAcsStatusState) {
|
||||
devicesStatuesList = state.allAcsStatues;
|
||||
devicesList = state.allAcs;
|
||||
allOn = state.allOn;
|
||||
allTempSame = state.allTempSame;
|
||||
temperature = state.temp;
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
child: state is AcChangeLoading || state is AcsLoadingState
|
||||
? const Center(
|
||||
child:
|
||||
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// universal AC controller
|
||||
const SizedBox(height: 10),
|
||||
const BodySmall(text: "All ACs"),
|
||||
const SizedBox(height: 5),
|
||||
// UniversalSwitch(
|
||||
// category: DevicesCubit.getInstance().chosenCategory!,
|
||||
// ),
|
||||
UniversalSwitch(
|
||||
allOn: allOn,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const UniversalACTemp(),
|
||||
UniversalACTemp(
|
||||
allTempSame: allTempSame,
|
||||
temp: temperature,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// other ACs controls
|
||||
@ -40,49 +62,40 @@ class ACsList extends StatelessWidget {
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
// itemCount: DevicesCubit.getInstance().chosenCategory!.devices!.length,
|
||||
itemCount: devicesList.length,
|
||||
itemBuilder: (context, index) {
|
||||
// DeviceModel ac = DevicesCubit.getInstance().chosenCategory!.devices![index];
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
// BodySmall(
|
||||
// text:
|
||||
// DevicesCubit.getInstance().chosenCategory!.devices![index].name ??
|
||||
// ""),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// DevicesCubit.getInstance().selectDevice(ac);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
),
|
||||
style: ButtonStyle(
|
||||
padding: MaterialStateProperty.all(
|
||||
const EdgeInsets.all(0),
|
||||
),
|
||||
iconSize: MaterialStateProperty.all(15),
|
||||
alignment: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
BodySmall(text: devicesList[index].name ?? ''),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
// DevicesDefaultSwitch(
|
||||
// model: ac,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// ACTempWidget(
|
||||
// ac,
|
||||
// ),
|
||||
// const SizedBox(height: 10),
|
||||
// ACModeControlUnit(
|
||||
// acDevice: ac,
|
||||
// ),
|
||||
DevicesDefaultSwitch(
|
||||
switchValue: devicesStatuesList[index].acSwitch,
|
||||
action: () {
|
||||
BlocProvider.of<ACsBloc>(context).add(AcSwitch(
|
||||
acSwitch: devicesStatuesList[index].acSwitch,
|
||||
deviceId: devicesList[index].uuid ?? ''));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ACTempWidget(
|
||||
deviceModel: devicesList[index],
|
||||
temp: devicesStatuesList[index].tempSet,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
ACModeControlUnit(
|
||||
acStatus: devicesStatuesList[index],
|
||||
deviceId: devicesList[index].uuid ?? '',
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
);
|
||||
|
@ -7,7 +7,6 @@ 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/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
@ -22,14 +21,10 @@ class ACsView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => ACsBloc(acId: deviceModel?.uuid ?? '')..add(AcsInitial()),
|
||||
create: (context) => ACsBloc(acId: deviceModel?.uuid ?? '')
|
||||
..add(AcsInitial(allAcs: deviceModel != null ? false : true)),
|
||||
child: BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
// 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),
|
||||
@ -43,7 +38,7 @@ class ACsView extends StatelessWidget {
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: BodyLarge(
|
||||
text: deviceModel?.name ?? "",
|
||||
text: deviceModel?.name ?? "ACs",
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
fontWeight: FontsManager.bold,
|
||||
),
|
||||
@ -67,9 +62,10 @@ class ACsView extends StatelessWidget {
|
||||
width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
: Container(
|
||||
padding: const EdgeInsets.only(top: 25),
|
||||
padding: const EdgeInsets.only(top: 40),
|
||||
alignment: AlignmentDirectional.center,
|
||||
child: deviceModel != null ? AcInterface(ac: deviceModel!) : ACsList(),
|
||||
child:
|
||||
deviceModel != null ? AcInterface(ac: deviceModel!) : const ACsList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -2,6 +2,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/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
@ -10,9 +11,9 @@ import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class UniversalACTemp extends StatelessWidget {
|
||||
const UniversalACTemp({
|
||||
super.key,
|
||||
});
|
||||
const UniversalACTemp({super.key, required this.temp, required this.allTempSame});
|
||||
final int temp;
|
||||
final bool allTempSame;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -27,8 +28,10 @@ class UniversalACTemp extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// DevicesCubit.getInstance()
|
||||
// .setTempToAll(DevicesCubit.universalACTemp - .5);
|
||||
double temperature = temp / 10;
|
||||
if (temperature < 30) {
|
||||
BlocProvider.of<ACsBloc>(context).add(DecreaseAllTemp(value: temperature));
|
||||
}
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsMinus,
|
||||
@ -36,8 +39,7 @@ class UniversalACTemp extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
BodyLarge(
|
||||
// text: "${DevicesCubit.universalACTemp}° C",
|
||||
text: '25 °C',
|
||||
text: '${allTempSame ? temp / 10 : '-'} °C',
|
||||
style: context.bodyLarge.copyWith(
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
fontSize: 23,
|
||||
@ -47,8 +49,10 @@ class UniversalACTemp extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
// DevicesCubit.getInstance()
|
||||
// .setTempToAll(DevicesCubit.universalACTemp + .5);
|
||||
double temperature = temp / 10;
|
||||
if (temperature > 20) {
|
||||
BlocProvider.of<ACsBloc>(context).add(IncreaseAllTemp(value: temperature));
|
||||
}
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsPlus,
|
||||
|
@ -41,7 +41,9 @@ class DevicesViewBody extends StatelessWidget {
|
||||
HomeCubit.getInstance().devicesPageChanged(index);
|
||||
},
|
||||
children: [
|
||||
const WizardPage(),
|
||||
WizardPage(
|
||||
groupsList: DevicesCubit.getInstance().allCategories ?? [],
|
||||
),
|
||||
if (HomeCubit.getInstance().selectedSpace != null)
|
||||
if (HomeCubit.getInstance().selectedSpace!.rooms != null)
|
||||
...HomeCubit.getInstance().selectedSpace!.rooms!.map(
|
||||
|
@ -87,6 +87,17 @@ class GateWayView extends StatelessWidget {
|
||||
),
|
||||
]),
|
||||
),
|
||||
if (devicesList.isEmpty && state is UpdateGatewayState)
|
||||
Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
alignment: AlignmentDirectional.center,
|
||||
child: const BodyMedium(
|
||||
text: 'No devices found',
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
if (devicesList.isNotEmpty)
|
||||
const BodyMedium(
|
||||
text: 'Zigbee Devices',
|
||||
fontSize: 15,
|
||||
|
@ -47,7 +47,10 @@ class LightsList extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(model: lights[index]),
|
||||
DevicesDefaultSwitch(
|
||||
switchValue: false,
|
||||
action: () {},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
LightBrightness(light: lights[index]),
|
||||
],
|
||||
|
@ -23,8 +23,8 @@ class LightsView extends StatelessWidget {
|
||||
selectedLight = DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
||||
}
|
||||
List<DeviceModel> lights = [];
|
||||
if (DevicesCubit.allCategories![1].devices != null) {
|
||||
for (var device in DevicesCubit.allCategories![1].devices!) {
|
||||
if (DevicesCubit.getInstance().allCategories![1].devices != null) {
|
||||
for (var device in DevicesCubit.getInstance().allCategories![1].devices!) {
|
||||
lights.add(device);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class LightsViewList extends StatelessWidget {
|
||||
children: [
|
||||
const BodySmall(text: "All Lights"),
|
||||
UniversalSwitch(
|
||||
category: DevicesCubit.allCategories![1],
|
||||
allOn: false,
|
||||
),
|
||||
LightsList(lights: lights),
|
||||
],
|
||||
|
@ -12,9 +12,7 @@ class RoomPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
child: BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return GridView.builder(
|
||||
child: GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 10,
|
||||
@ -28,8 +26,6 @@ class RoomPage extends StatelessWidget {
|
||||
itemBuilder: (context, index) {
|
||||
return RoomPageSwitch(device: room.devices![index]);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_screen.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
@ -10,9 +9,9 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||
|
||||
class ThreeGangInterface extends StatelessWidget {
|
||||
const ThreeGangInterface({super.key, required this.gangSwitch});
|
||||
const ThreeGangInterface({super.key, this.gangSwitch});
|
||||
|
||||
final DeviceModel gangSwitch;
|
||||
final DeviceModel? gangSwitch;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnnotatedRegion(
|
||||
@ -28,7 +27,7 @@ class ThreeGangInterface extends StatelessWidget {
|
||||
backgroundColor: Colors.transparent,
|
||||
centerTitle: true,
|
||||
title: BodyLarge(
|
||||
text: gangSwitch.name ?? "",
|
||||
text: gangSwitch?.name ?? 'Lights',
|
||||
fontColor: ColorsManager.primaryColor,
|
||||
fontWeight: FontsManager.bold,
|
||||
),
|
||||
@ -53,9 +52,7 @@ class ThreeGangInterface extends StatelessWidget {
|
||||
right: Constants.defaultPadding,
|
||||
bottom: Constants.bottomNavBarHeight,
|
||||
),
|
||||
child: ThreeGangScreen(
|
||||
device: gangSwitch,
|
||||
),
|
||||
child: ThreeGangScreen(device: gangSwitch),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/group_three_gang_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/devices_default_switch.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
|
||||
class ThreeGangList extends StatelessWidget {
|
||||
const ThreeGangList({super.key, required this.threeGangList, required this.allSwitches});
|
||||
|
||||
final List<GroupThreeGangModel> threeGangList;
|
||||
final bool allSwitches;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ThreeGangBloc, ThreeGangState>(
|
||||
builder: (context, state) {
|
||||
return state is LoadingNewSate
|
||||
? const Center(
|
||||
child: DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
const BodySmall(text: 'All Lights'),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(
|
||||
switchValue: allSwitches,
|
||||
action: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(GroupAllOnEvent());
|
||||
},
|
||||
secondAction: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(GroupAllOffEvent());
|
||||
},
|
||||
),
|
||||
ListView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.all(0),
|
||||
itemCount: threeGangList.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
BodySmall(text: '${threeGangList[index].deviceName} beside light'),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(
|
||||
switchValue: threeGangList[index].firstSwitch,
|
||||
action: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(
|
||||
ChangeFirstSwitchStatusEvent(
|
||||
value: threeGangList[index].firstSwitch,
|
||||
deviceId: threeGangList[index].deviceId));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BodySmall(text: '${threeGangList[index].deviceName} ceiling light'),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(
|
||||
switchValue: threeGangList[index].secondSwitch,
|
||||
action: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(
|
||||
ChangeSecondSwitchStatusEvent(
|
||||
value: threeGangList[index].secondSwitch,
|
||||
deviceId: threeGangList[index].deviceId));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
BodySmall(text: '${threeGangList[index].deviceName} spotlight'),
|
||||
const SizedBox(height: 5),
|
||||
DevicesDefaultSwitch(
|
||||
switchValue: threeGangList[index].thirdSwitch,
|
||||
action: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(
|
||||
ChangeThirdSwitchStatusEvent(
|
||||
value: threeGangList[index].thirdSwitch,
|
||||
deviceId: threeGangList[index].deviceId));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -4,26 +4,26 @@ import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_blo
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/three_gang_bloc/three_gang_state.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/group_three_gang_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/three_gang_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/gang_switch.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/schedule_screen.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_list.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_small.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class ThreeGangScreen extends StatelessWidget {
|
||||
const ThreeGangScreen({
|
||||
super.key,
|
||||
required this.device,
|
||||
});
|
||||
const ThreeGangScreen({super.key, this.device});
|
||||
|
||||
final DeviceModel device;
|
||||
final DeviceModel? device;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => ThreeGangBloc(threeGangId: device.uuid ?? '')..add(InitialEvent()),
|
||||
create: (context) => ThreeGangBloc(threeGangId: device?.uuid ?? '')
|
||||
..add(InitialEvent(groupScreen: device != null ? false : true)),
|
||||
child: BlocBuilder<ThreeGangBloc, ThreeGangState>(
|
||||
builder: (context, state) {
|
||||
ThreeGangModel threeGangModel = ThreeGangModel(
|
||||
@ -33,16 +33,28 @@ class ThreeGangScreen extends StatelessWidget {
|
||||
firstCountDown: 0,
|
||||
secondCountDown: 0,
|
||||
thirdCountDown: 0);
|
||||
|
||||
List<GroupThreeGangModel> groupThreeGangModel = [];
|
||||
bool allSwitchesOn = false;
|
||||
|
||||
if (state is LoadingNewSate) {
|
||||
threeGangModel = state.threeGangModel;
|
||||
} else if (state is UpdateState) {
|
||||
threeGangModel = state.threeGangModel;
|
||||
} else if (state is UpdateGroupState) {
|
||||
groupThreeGangModel = state.threeGangList;
|
||||
allSwitchesOn = state.allSwitches;
|
||||
}
|
||||
return state is LoadingInitialState
|
||||
? const Center(
|
||||
child:
|
||||
DefaultContainer(width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
: device == null
|
||||
? ThreeGangList(
|
||||
threeGangList: groupThreeGangModel,
|
||||
allSwitches: allSwitchesOn,
|
||||
)
|
||||
: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
@ -55,7 +67,7 @@ class ThreeGangScreen extends StatelessWidget {
|
||||
Column(
|
||||
children: [
|
||||
GangSwitch(
|
||||
threeGangSwitch: device,
|
||||
threeGangSwitch: device!,
|
||||
value: threeGangModel.firstSwitch,
|
||||
action: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(
|
||||
@ -84,7 +96,7 @@ class ThreeGangScreen extends StatelessWidget {
|
||||
Column(
|
||||
children: [
|
||||
GangSwitch(
|
||||
threeGangSwitch: device,
|
||||
threeGangSwitch: device!,
|
||||
value: threeGangModel.secondSwitch,
|
||||
action: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(
|
||||
@ -114,7 +126,7 @@ class ThreeGangScreen extends StatelessWidget {
|
||||
Column(
|
||||
children: [
|
||||
GangSwitch(
|
||||
threeGangSwitch: device,
|
||||
threeGangSwitch: device!,
|
||||
value: threeGangModel.thirdSwitch,
|
||||
action: () {
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(
|
||||
@ -235,7 +247,7 @@ class ThreeGangScreen extends StatelessWidget {
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation1, animation2) =>
|
||||
ScheduleScreen(
|
||||
device: device,
|
||||
device: device!,
|
||||
)));
|
||||
},
|
||||
child: Stack(
|
||||
@ -314,7 +326,8 @@ class ThreeGangScreen extends StatelessWidget {
|
||||
// ),
|
||||
// device.uuid!,
|
||||
// );
|
||||
BlocProvider.of<ThreeGangBloc>(context).add(AllOffEvent());
|
||||
BlocProvider.of<ThreeGangBloc>(context)
|
||||
.add(AllOffEvent());
|
||||
},
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
|
@ -1,7 +1,8 @@
|
||||
import 'package:flutter/material.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_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||
@ -9,31 +10,27 @@ import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
||||
class UniversalSwitch extends StatelessWidget {
|
||||
const UniversalSwitch({
|
||||
super.key,
|
||||
required this.category,
|
||||
required this.allOn,
|
||||
});
|
||||
|
||||
final DevicesCategoryModel category;
|
||||
final bool allOn;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
bool? status = category.devicesStatus;
|
||||
// bool? status = category.devicesStatus;
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
DevicesCubit.getInstance().turnAllDevicesOn(category);
|
||||
BlocProvider.of<ACsBloc>(context).add(const ChangeAllSwitch(value: true));
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: status != null
|
||||
? status
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.white
|
||||
: Colors.white,
|
||||
color: allOn ? ColorsManager.primaryColor : Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15),
|
||||
@ -42,11 +39,7 @@ class UniversalSwitch extends StatelessWidget {
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: StringsManager.on,
|
||||
fontColor: status != null
|
||||
? status
|
||||
? Colors.white
|
||||
: null
|
||||
: null,
|
||||
fontColor: allOn ? Colors.white : null,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@ -56,16 +49,12 @@ class UniversalSwitch extends StatelessWidget {
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
DevicesCubit.getInstance().turnAllDevicesOff(category);
|
||||
BlocProvider.of<ACsBloc>(context).add(const ChangeAllSwitch(value: false));
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: status != null
|
||||
? status
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor
|
||||
: Colors.white,
|
||||
color: allOn ? Colors.white : ColorsManager.primaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15),
|
||||
@ -74,11 +63,7 @@ class UniversalSwitch extends StatelessWidget {
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: StringsManager.off,
|
||||
fontColor: status != null
|
||||
? status
|
||||
? null
|
||||
: Colors.white
|
||||
: null,
|
||||
fontColor: allOn ? null : Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
@ -1,17 +1,79 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/wizard_switches.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_category_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.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';
|
||||
|
||||
class WizardPage extends StatelessWidget {
|
||||
const WizardPage({
|
||||
super.key,
|
||||
});
|
||||
final List<DevicesCategoryModel> groupsList;
|
||||
const WizardPage({super.key, required this.groupsList});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const SingleChildScrollView(
|
||||
child: WizartSwitches(),
|
||||
return GridView.builder(
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
childAspectRatio: 1.5,
|
||||
),
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
shrinkWrap: true,
|
||||
itemCount: groupsList.length,
|
||||
itemBuilder: (_, index) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
if (groupsList[index].name == 'AC') {
|
||||
Navigator.push(
|
||||
context,
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation1, animation2) => const ACsView()));
|
||||
}
|
||||
if (groupsList[index].name == '3G') {
|
||||
Navigator.push(
|
||||
context,
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation1, animation2) =>
|
||||
const ThreeGangInterface()));
|
||||
}
|
||||
},
|
||||
child: DefaultContainer(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
groupsList[index].icon!,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
// CustomSwitch(
|
||||
],
|
||||
),
|
||||
FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: BodyLarge(
|
||||
text: groupsList[index].name!,
|
||||
style: context.bodyLarge.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 0,
|
||||
fontSize: 20,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,97 +0,0 @@
|
||||
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/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';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
|
||||
|
||||
class WizartSwitches extends StatelessWidget {
|
||||
const WizartSwitches({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return state is! DevicesLoading
|
||||
? DevicesCubit.allCategories != null
|
||||
? GridView.builder(
|
||||
gridDelegate:
|
||||
const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 10,
|
||||
mainAxisSpacing: 10,
|
||||
childAspectRatio: 1.5,
|
||||
),
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: DevicesCubit.allCategories!.length,
|
||||
itemBuilder: (_, index) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
// DevicesCubit.getInstance().selectCategory(index);
|
||||
//Navigate to the chosen category view without animation
|
||||
if (DevicesCubit.getInstance().chosenCategoryView ==
|
||||
null) {
|
||||
return;
|
||||
}
|
||||
Navigator.push(context,
|
||||
CustomPageRoute(builder: (context) {
|
||||
return DevicesCubit.getInstance()
|
||||
.chosenCategoryView!;
|
||||
}));
|
||||
},
|
||||
child: DefaultContainer(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 10, right: 10, left: 10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
DevicesCubit.allCategories![index].icon!,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
// CustomSwitch(
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.scaleDown,
|
||||
child: BodyLarge(
|
||||
text: DevicesCubit
|
||||
.allCategories![index].name!,
|
||||
style: context.bodyLarge.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 0,
|
||||
fontSize: 24,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
: const SizedBox.shrink()
|
||||
: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
@ -1,35 +1,28 @@
|
||||
import 'package:flutter/material.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/shared_widgets/text_widgets/body_medium.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
class DevicesDefaultSwitch extends StatelessWidget {
|
||||
const DevicesDefaultSwitch({
|
||||
super.key,
|
||||
required this.model,
|
||||
});
|
||||
const DevicesDefaultSwitch(
|
||||
{super.key, required this.switchValue, required this.action, this.secondAction});
|
||||
|
||||
final DeviceModel model;
|
||||
final bool switchValue;
|
||||
final Function action;
|
||||
final Function? secondAction;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<DevicesCubit, DevicesState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
DevicesCubit.getInstance().turnOnOffDevice(model);
|
||||
action();
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: model.isOnline ?? false
|
||||
? ColorsManager.primaryColor
|
||||
: Colors.white,
|
||||
color: switchValue ? ColorsManager.primaryColor : Colors.white,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(15),
|
||||
bottomLeft: Radius.circular(15),
|
||||
@ -38,7 +31,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "ON",
|
||||
fontColor: model.isOnline ?? false ? Colors.white : null,
|
||||
fontColor: switchValue ? Colors.white : null,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@ -48,14 +41,16 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
Expanded(
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
DevicesCubit.getInstance().turnOnOffDevice(model);
|
||||
if (secondAction != null) {
|
||||
secondAction!();
|
||||
} else {
|
||||
action();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
height: 60,
|
||||
decoration: BoxDecoration(
|
||||
color: model.isOnline ?? false
|
||||
? Colors.white
|
||||
: ColorsManager.primaryColor,
|
||||
color: switchValue ? Colors.white : ColorsManager.primaryColor,
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(15),
|
||||
bottomRight: Radius.circular(15),
|
||||
@ -64,7 +59,7 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
child: Center(
|
||||
child: BodyMedium(
|
||||
text: "OFF",
|
||||
fontColor: model.isOnline ?? false ? null : Colors.white,
|
||||
fontColor: switchValue ? null : Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
@ -73,7 +68,5 @@ class DevicesDefaultSwitch extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ class Assets {
|
||||
/// Assets for assetsIconsAutomatedClock
|
||||
/// assets/icons/automated_clock.svg
|
||||
static const String assetsIconsAutomatedClock = "assets/icons/automated_clock.svg";
|
||||
static const String acSwitchIcon = "assets/icons/ac_switch_ic.svg";
|
||||
|
||||
/// Assets for assetsIconsBatteryDmOffPerOffchargOfflowOffpmOffstChargeddmOff
|
||||
/// assets/icons/battery/dmOff/perOffchargOfflowOffpmOffstChargeddmOff.svg
|
||||
|
@ -79,7 +79,9 @@ abstract class ApiEndpoints {
|
||||
static const String addGroup = '$baseUrl/group';
|
||||
static const String controlGroup = '$baseUrl/group/control';
|
||||
//GET
|
||||
static const String groupBySpace = '$baseUrl/group/space/{spaceUuid}';
|
||||
static const String groupBySpace = '$baseUrl/group/{unitUuid}';
|
||||
static const String devicesByGroupName = '$baseUrl/group/{unitUuid}/devices/{groupName}';
|
||||
|
||||
static const String groupByUuid = '$baseUrl/group/{groupUuid}';
|
||||
//DELETE
|
||||
static const String deleteGroup = '$baseUrl/group/{groupUuid}';
|
||||
@ -96,7 +98,7 @@ abstract class ApiEndpoints {
|
||||
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 gatewayApi = '$baseUrl/device/getaway/{gatewayUuid}/devices';
|
||||
static const String gatewayApi = '$baseUrl/device/gateway/{gatewayUuid}/devices';
|
||||
static const String deviceFunctionsStatus = '$baseUrl/device/{deviceUuid}/functions/status';
|
||||
|
||||
///Device Permission Module
|
||||
|
@ -27,13 +27,13 @@ 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,
|
||||
path: ApiEndpoints.groupBySpace.replaceAll('{unitUuid}', spaceId),
|
||||
// queryParameters: params,
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => DevicesCategoryModel.fromJsonList(json['groups']),
|
||||
expectedResponseModel: (json) => DevicesCategoryModel.fromJsonList(json),
|
||||
);
|
||||
return response;
|
||||
}
|
||||
@ -49,6 +49,26 @@ class DevicesAPI {
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future<List<DeviceModel>> getDeviceByGroupName(String unitId, String groupName) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.devicesByGroupName
|
||||
.replaceAll('{unitUuid}', unitId)
|
||||
.replaceAll('{groupName}', groupName),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
if (json == null || json.isEmpty || json == []) {
|
||||
return <DeviceModel>[];
|
||||
}
|
||||
List<DeviceModel> devices = [];
|
||||
for (var device in json) {
|
||||
devices.add(DeviceModel.fromJson(device));
|
||||
}
|
||||
return devices;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
static Future<List<DeviceModel>> getDevicesByRoomId(String roomId) async {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.deviceByRoom,
|
||||
|
Reference in New Issue
Block a user