mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
finished AC
This commit is contained in:
@ -1,31 +1,21 @@
|
||||
import 'dart:async';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
|
||||
class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
AcStatusModel deviceStatus = AcStatusModel(
|
||||
uuid: '',
|
||||
acSwitch: true,
|
||||
modeString: 'hot',
|
||||
tempSet: 300,
|
||||
currentTemp: 315,
|
||||
fanSpeedsString: 'low',
|
||||
childLock: false,
|
||||
);
|
||||
late AcStatusModel deviceStatus;
|
||||
final String deviceId;
|
||||
Timer? _timer;
|
||||
|
||||
AcBloc() : super(AcsInitialState()) {
|
||||
AcBloc({required this.deviceId}) : super(AcsInitialState()) {
|
||||
on<AcFetchDeviceStatus>(_onFetchAcStatus);
|
||||
on<AcControl>(_onAcControl);
|
||||
on<AcSwitch>(_changeAcSwitch);
|
||||
on<IncreaseCoolToTemp>(_increaseCoolTo);
|
||||
on<DecreaseCoolToTemp>(_decreaseCoolTo);
|
||||
on<ChangeLock>(_changeLockValue);
|
||||
on<ChangeAcMode>(_changeAcMode);
|
||||
on<ChangeFanSpeed>(_changeFanSpeed);
|
||||
}
|
||||
|
||||
FutureOr<void> _onFetchAcStatus(
|
||||
@ -34,7 +24,7 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
try {
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
deviceStatus = AcStatusModel.fromJson(status.productUuid, status.status);
|
||||
deviceStatus = AcStatusModel.fromJson(event.deviceId, status.status);
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
@ -45,47 +35,86 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
final oldValue = _getValueByCode(event.code);
|
||||
|
||||
_updateLocalValue(event.code, event.value);
|
||||
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
|
||||
try {
|
||||
final status = Status(code: event.code, value: event.value);
|
||||
final response =
|
||||
await DevicesManagementApi().deviceControl(event.deviceId, status);
|
||||
await _runDebounce(
|
||||
deviceId: event.deviceId,
|
||||
code: event.code,
|
||||
value: event.value,
|
||||
oldValue: oldValue,
|
||||
emit: emit,
|
||||
);
|
||||
}
|
||||
|
||||
if (!response) {
|
||||
_updateLocalValue(event.code, oldValue);
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(AcsFailedState(error: 'Failed to control the device.'));
|
||||
}
|
||||
} catch (e) {
|
||||
_updateLocalValue(event.code, oldValue);
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(AcsFailedState(error: 'Error controlling the device: $e'));
|
||||
Future<void> _runDebounce({
|
||||
required String deviceId,
|
||||
required String code,
|
||||
required dynamic value,
|
||||
required dynamic oldValue,
|
||||
required Emitter<AcsState> emit,
|
||||
}) async {
|
||||
if (_timer != null) {
|
||||
_timer!.cancel();
|
||||
}
|
||||
_timer = Timer(const Duration(seconds: 1), () async {
|
||||
try {
|
||||
final response = await DevicesManagementApi()
|
||||
.deviceControl(deviceId, Status(code: code, value: value));
|
||||
if (!response) {
|
||||
_revertValueAndEmit(deviceId, code, oldValue, emit);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e is DioException && e.response != null) {
|
||||
debugPrint('Error response: ${e.response?.data}');
|
||||
}
|
||||
_revertValueAndEmit(deviceId, code, oldValue, emit);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _revertValueAndEmit(
|
||||
String deviceId, String code, dynamic oldValue, Emitter<AcsState> emit) {
|
||||
_updateLocalValue(code, oldValue);
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
emit(const AcsFailedState(error: 'Failed to control the device.'));
|
||||
}
|
||||
|
||||
void _updateLocalValue(String code, dynamic value) {
|
||||
switch (code) {
|
||||
case 'switch':
|
||||
deviceStatus.acSwitch = value;
|
||||
if (value is bool) {
|
||||
deviceStatus = deviceStatus.copyWith(acSwitch: value);
|
||||
}
|
||||
break;
|
||||
case 'temp_set':
|
||||
deviceStatus.tempSet = value;
|
||||
if (value is int) {
|
||||
deviceStatus = deviceStatus.copyWith(tempSet: value);
|
||||
}
|
||||
break;
|
||||
case 'mode':
|
||||
deviceStatus.modeString = value;
|
||||
deviceStatus.acMode = AcStatusModel.getACMode(value);
|
||||
if (value is String) {
|
||||
deviceStatus = deviceStatus.copyWith(
|
||||
modeString: value,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'level':
|
||||
deviceStatus.fanSpeedsString = value;
|
||||
deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(value);
|
||||
if (value is String) {
|
||||
deviceStatus = deviceStatus.copyWith(
|
||||
fanSpeedsString: value,
|
||||
);
|
||||
}
|
||||
break;
|
||||
case 'child_lock':
|
||||
deviceStatus.childLock = value;
|
||||
if (value is bool) {
|
||||
deviceStatus = deviceStatus.copyWith(childLock: value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
emit(ACStatusLoaded(deviceStatus));
|
||||
}
|
||||
|
||||
dynamic _getValueByCode(String code) {
|
||||
@ -104,50 +133,4 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _changeAcSwitch(AcSwitch event, Emitter<AcsState> emit) async {
|
||||
final newValue = !event.acSwitch;
|
||||
add(AcControl(deviceId: event.deviceId, code: 'switch', value: newValue));
|
||||
}
|
||||
|
||||
FutureOr<void> _increaseCoolTo(
|
||||
IncreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
final newValue = (event.value * 10).toInt() + 5;
|
||||
if (_isValidTemperature(newValue)) {
|
||||
add(AcControl(
|
||||
deviceId: event.deviceId, code: 'temp_set', value: newValue));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _decreaseCoolTo(
|
||||
DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
final newValue = (event.value * 10).toInt() - 5;
|
||||
if (_isValidTemperature(newValue)) {
|
||||
add(AcControl(
|
||||
deviceId: event.deviceId, code: 'temp_set', value: newValue));
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _changeLockValue(
|
||||
ChangeLock event, Emitter<AcsState> emit) async {
|
||||
final newValue = !event.lockBool;
|
||||
add(AcControl(
|
||||
deviceId: event.deviceId, code: 'child_lock', value: newValue));
|
||||
}
|
||||
|
||||
FutureOr<void> _changeAcMode(
|
||||
ChangeAcMode event, Emitter<AcsState> emit) async {
|
||||
final newValue = AcStatusModel.getACMode(event.tempModes.name);
|
||||
add(AcControl(deviceId: event.deviceId, code: 'mode', value: newValue));
|
||||
}
|
||||
|
||||
FutureOr<void> _changeFanSpeed(
|
||||
ChangeFanSpeed event, Emitter<AcsState> emit) async {
|
||||
final newValue = AcStatusModel.getFanSpeed(event.fanSpeeds.name);
|
||||
add(AcControl(deviceId: event.deviceId, code: 'level', value: newValue));
|
||||
}
|
||||
|
||||
bool _isValidTemperature(int value) {
|
||||
return value >= 200 && value <= 300;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
|
||||
sealed class AcsEvent extends Equatable {
|
||||
const AcsEvent();
|
||||
@ -31,63 +30,3 @@ class AcControl extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [deviceId, code, value];
|
||||
}
|
||||
|
||||
class AcSwitch extends AcsEvent {
|
||||
final bool acSwitch;
|
||||
final String deviceId;
|
||||
|
||||
const AcSwitch({required this.acSwitch, required this.deviceId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [acSwitch, deviceId];
|
||||
}
|
||||
|
||||
class IncreaseCoolToTemp extends AcsEvent {
|
||||
final double value;
|
||||
final String deviceId;
|
||||
|
||||
const IncreaseCoolToTemp({required this.value, required this.deviceId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value, deviceId];
|
||||
}
|
||||
|
||||
class DecreaseCoolToTemp extends AcsEvent {
|
||||
final double value;
|
||||
final String deviceId;
|
||||
|
||||
const DecreaseCoolToTemp({required this.value, required this.deviceId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value, deviceId];
|
||||
}
|
||||
|
||||
class ChangeLock extends AcsEvent {
|
||||
final bool lockBool;
|
||||
final String deviceId;
|
||||
|
||||
const ChangeLock({required this.lockBool, required this.deviceId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [lockBool, deviceId];
|
||||
}
|
||||
|
||||
class ChangeAcMode extends AcsEvent {
|
||||
final TempModes tempModes;
|
||||
final String deviceId;
|
||||
|
||||
const ChangeAcMode({required this.tempModes, required this.deviceId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempModes, deviceId];
|
||||
}
|
||||
|
||||
class ChangeFanSpeed extends AcsEvent {
|
||||
final FanSpeeds fanSpeeds;
|
||||
final String deviceId;
|
||||
|
||||
const ChangeFanSpeed({required this.fanSpeeds, required this.deviceId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [fanSpeeds, deviceId];
|
||||
}
|
||||
|
@ -14,56 +14,12 @@ class AcsLoadingState extends AcsState {}
|
||||
|
||||
class ACStatusLoaded extends AcsState {
|
||||
final AcStatusModel status;
|
||||
final DateTime timestamp;
|
||||
|
||||
const ACStatusLoaded(this.status);
|
||||
ACStatusLoaded(this.status) : timestamp = DateTime.now();
|
||||
|
||||
@override
|
||||
List<Object> get props => [status];
|
||||
}
|
||||
|
||||
class AcSwitchChanged extends AcsState {
|
||||
final bool acSwitch;
|
||||
|
||||
const AcSwitchChanged(this.acSwitch);
|
||||
|
||||
@override
|
||||
List<Object> get props => [acSwitch];
|
||||
}
|
||||
|
||||
class AcTempChanged extends AcsState {
|
||||
final double tempSet;
|
||||
|
||||
const AcTempChanged(this.tempSet);
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempSet];
|
||||
}
|
||||
|
||||
class AcModeChanged extends AcsState {
|
||||
final TempModes mode;
|
||||
|
||||
const AcModeChanged(this.mode);
|
||||
|
||||
@override
|
||||
List<Object> get props => [mode];
|
||||
}
|
||||
|
||||
class AcFanSpeedChanged extends AcsState {
|
||||
final FanSpeeds fanSpeed;
|
||||
|
||||
const AcFanSpeedChanged(this.fanSpeed);
|
||||
|
||||
@override
|
||||
List<Object> get props => [fanSpeed];
|
||||
}
|
||||
|
||||
class AcLockChanged extends AcsState {
|
||||
final bool lock;
|
||||
|
||||
const AcLockChanged(this.lock);
|
||||
|
||||
@override
|
||||
List<Object> get props => [lock];
|
||||
List<Object> get props => [status, timestamp];
|
||||
}
|
||||
|
||||
class AcsFailedState extends AcsState {
|
||||
|
@ -5,83 +5,114 @@ enum TempModes { hot, cold, wind }
|
||||
enum FanSpeeds { auto, low, middle, high }
|
||||
|
||||
class AcStatusModel {
|
||||
String uuid;
|
||||
bool acSwitch;
|
||||
String modeString;
|
||||
int tempSet;
|
||||
int currentTemp;
|
||||
String fanSpeedsString;
|
||||
bool childLock;
|
||||
late TempModes acMode;
|
||||
late FanSpeeds acFanSpeed;
|
||||
final String uuid;
|
||||
final bool acSwitch;
|
||||
final String modeString;
|
||||
final int tempSet;
|
||||
final int currentTemp;
|
||||
final String fanSpeedsString;
|
||||
final bool childLock;
|
||||
final TempModes acMode;
|
||||
final FanSpeeds acFanSpeed;
|
||||
|
||||
AcStatusModel(
|
||||
{required this.uuid,
|
||||
required this.acSwitch,
|
||||
required this.modeString,
|
||||
required this.tempSet,
|
||||
required this.currentTemp,
|
||||
required this.fanSpeedsString,
|
||||
required this.childLock}) {
|
||||
acMode = getACMode(modeString);
|
||||
acFanSpeed = getFanSpeed(fanSpeedsString);
|
||||
}
|
||||
AcStatusModel({
|
||||
required this.uuid,
|
||||
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(String id, List<Status> 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;
|
||||
late bool acSwitch;
|
||||
late String mode;
|
||||
late int tempSet;
|
||||
late int currentTemp;
|
||||
late String fanSpeeds;
|
||||
late bool childLock;
|
||||
|
||||
for (var status in jsonList) {
|
||||
switch (status.code) {
|
||||
case 'switch':
|
||||
acSwitch = status.value ?? false;
|
||||
break;
|
||||
case 'mode':
|
||||
mode = status.value ?? 'cold'; // default to 'cold' if null
|
||||
break;
|
||||
case 'temp_set':
|
||||
tempSet = status.value ?? 210; // default value if null
|
||||
break;
|
||||
case 'temp_current':
|
||||
currentTemp = status.value ?? 210; // default value if null
|
||||
break;
|
||||
case 'level':
|
||||
fanSpeeds = status.value ?? 'low'; // default value if null
|
||||
break;
|
||||
case 'child_lock':
|
||||
childLock = status.value ?? false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return AcStatusModel(
|
||||
uuid: id,
|
||||
acSwitch: _acSwitch,
|
||||
modeString: _mode,
|
||||
tempSet: _tempSet,
|
||||
currentTemp: _currentTemp,
|
||||
fanSpeedsString: _fanSpeeds,
|
||||
childLock: _childLock);
|
||||
uuid: id,
|
||||
acSwitch: acSwitch,
|
||||
modeString: mode,
|
||||
tempSet: tempSet,
|
||||
currentTemp: currentTemp,
|
||||
fanSpeedsString: fanSpeeds,
|
||||
childLock: childLock,
|
||||
);
|
||||
}
|
||||
|
||||
AcStatusModel copyWith({
|
||||
String? uuid,
|
||||
bool? acSwitch,
|
||||
String? modeString,
|
||||
int? tempSet,
|
||||
int? currentTemp,
|
||||
String? fanSpeedsString,
|
||||
bool? childLock,
|
||||
}) {
|
||||
return AcStatusModel(
|
||||
uuid: uuid ?? this.uuid,
|
||||
acSwitch: acSwitch ?? this.acSwitch,
|
||||
modeString: modeString ?? this.modeString,
|
||||
tempSet: tempSet ?? this.tempSet,
|
||||
currentTemp: currentTemp ?? this.currentTemp,
|
||||
fanSpeedsString: fanSpeedsString ?? this.fanSpeedsString,
|
||||
childLock: childLock ?? this.childLock,
|
||||
);
|
||||
}
|
||||
|
||||
static 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;
|
||||
switch (value) {
|
||||
case 'cold':
|
||||
return TempModes.cold;
|
||||
case 'hot':
|
||||
return TempModes.hot;
|
||||
case 'wind':
|
||||
return TempModes.wind;
|
||||
default:
|
||||
return TempModes.cold;
|
||||
}
|
||||
}
|
||||
|
||||
static 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;
|
||||
switch (value) {
|
||||
case 'low':
|
||||
return FanSpeeds.low;
|
||||
case 'middle':
|
||||
return FanSpeeds.middle;
|
||||
case 'high':
|
||||
return FanSpeeds.high;
|
||||
case 'auto':
|
||||
return FanSpeeds.auto;
|
||||
default:
|
||||
return FanSpeeds.auto;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,9 @@ import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_state.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/ac_mode.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/ac_toggle.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/current_temp.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/view/control_list/fan_speed.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
@ -20,13 +21,58 @@ class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
final isLarge = isLargeScreenSize(context);
|
||||
final isMedium = isMediumScreenSize(context);
|
||||
return BlocProvider(
|
||||
create: (context) => AcBloc()..add(AcFetchDeviceStatus(device.uuid!)),
|
||||
create: (context) => AcBloc(deviceId: device.uuid!)
|
||||
..add(AcFetchDeviceStatus(device.uuid!)),
|
||||
child: BlocBuilder<AcBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
if (state is AcsLoadingState) {
|
||||
if (state is ACStatusLoaded) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: isLarge
|
||||
? 3
|
||||
: isMedium
|
||||
? 2
|
||||
: 1,
|
||||
mainAxisExtent: 133,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
children: [
|
||||
AcToggle(
|
||||
value: state.status.acSwitch,
|
||||
code: 'switch',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
CurrentTemp(
|
||||
currentTemp: state.status.currentTemp,
|
||||
tempSet: state.status.tempSet,
|
||||
code: 'temp_set',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
AcMode(
|
||||
value: state.status.acMode,
|
||||
code: 'mode',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
FanSpeedControl(
|
||||
value: state.status.acFanSpeed,
|
||||
code: 'level',
|
||||
deviceId: device.uuid!,
|
||||
),
|
||||
AcToggle(
|
||||
value: state.status.childLock,
|
||||
code: 'child_lock',
|
||||
deviceId: device.uuid!,
|
||||
description: 'Child Lock',
|
||||
icon: Assets.childLock,
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (state is AcsLoadingState) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is ACStatusLoaded) {
|
||||
return _buildStatusControls(state.status, isLarge, isMedium);
|
||||
} else {
|
||||
return const Center(child: Text('Error fetching status'));
|
||||
}
|
||||
@ -34,40 +80,4 @@ class AcDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusControls(AcStatusModel statuses, bool isLarge, bool isMedium) {
|
||||
return GridView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: isLarge
|
||||
? 3
|
||||
: isMedium
|
||||
? 2
|
||||
: 1,
|
||||
mainAxisExtent: 133,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
children: [
|
||||
AcToggle(
|
||||
value: statuses.acSwitch,
|
||||
code: 'switch',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
AcMode(
|
||||
value: statuses.acMode,
|
||||
code: 'mode',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
CurrentTemp(
|
||||
currentTemp: statuses.currentTemp,
|
||||
tempSet: statuses.tempSet,
|
||||
code: 'temp_set',
|
||||
deviceId: statuses.uuid,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,6 @@ class AcMode extends StatelessWidget {
|
||||
final String code;
|
||||
final String deviceId;
|
||||
|
||||
void _onModeSelected(BuildContext context, TempModes mode) {
|
||||
context.read<AcBloc>().add(
|
||||
ChangeAcMode(tempModes: mode, deviceId: deviceId),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
@ -54,7 +48,13 @@ class AcMode extends StatelessWidget {
|
||||
return Flexible(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
_onModeSelected(context, mode);
|
||||
context.read<AcBloc>().add(
|
||||
AcControl(
|
||||
deviceId: deviceId,
|
||||
code: code,
|
||||
value: mode.name,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
|
@ -53,7 +53,7 @@ class _CurrentTempState extends State<CurrentTemp> {
|
||||
AcControl(
|
||||
deviceId: widget.deviceId,
|
||||
code: widget.code,
|
||||
value: newValue * 10,
|
||||
value: (newValue * 10).toInt(),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
@ -0,0 +1,91 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/model/ac_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_bloc.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/ac/bloc/ac_event.dart';
|
||||
|
||||
class FanSpeedControl extends StatelessWidget {
|
||||
const FanSpeedControl({
|
||||
super.key,
|
||||
required this.value,
|
||||
required this.code,
|
||||
required this.deviceId,
|
||||
});
|
||||
|
||||
final FanSpeeds value;
|
||||
final String code;
|
||||
final String deviceId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: ColorsManager.greyColor.withOpacity(0.2),
|
||||
border: Border.all(color: ColorsManager.boxDivider),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
children: [
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
children: [
|
||||
_buildIconContainer(context, FanSpeeds.auto, Assets.acFanAuto,
|
||||
value == FanSpeeds.auto),
|
||||
_buildIconContainer(context, FanSpeeds.low, Assets.acFanLow,
|
||||
value == FanSpeeds.low),
|
||||
],
|
||||
),
|
||||
Wrap(
|
||||
runSpacing: 8,
|
||||
spacing: 8,
|
||||
children: [
|
||||
_buildIconContainer(context, FanSpeeds.middle, Assets.acFanMiddle,
|
||||
value == FanSpeeds.middle),
|
||||
_buildIconContainer(context, FanSpeeds.high, Assets.acFanHigh,
|
||||
value == FanSpeeds.high),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconContainer(BuildContext context, FanSpeeds speed,
|
||||
String assetPath, bool isSelected) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
context.read<AcBloc>().add(
|
||||
AcControl(
|
||||
deviceId: deviceId,
|
||||
code: code,
|
||||
value: speed.name,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: ColorsManager.whiteColors,
|
||||
border: Border.all(
|
||||
color: isSelected ? Colors.blue : Colors.transparent,
|
||||
width: 2.0,
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: ClipOval(
|
||||
child: SvgPicture.asset(
|
||||
assetPath,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -24,20 +24,18 @@ class IncrementDecrementWidget extends StatelessWidget {
|
||||
children: [
|
||||
Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Flexible(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: InkWell(
|
||||
splashColor: Colors.transparent,
|
||||
highlightColor: Colors.transparent,
|
||||
onTap: onDecrement,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
color: ColorsManager.greyColor,
|
||||
size: 28,
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: InkWell(
|
||||
splashColor: Colors.transparent,
|
||||
highlightColor: Colors.transparent,
|
||||
onTap: onDecrement,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.remove,
|
||||
color: ColorsManager.greyColor,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -73,20 +71,18 @@ class IncrementDecrementWidget extends StatelessWidget {
|
||||
),
|
||||
Material(
|
||||
type: MaterialType.transparency,
|
||||
child: Flexible(
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: InkWell(
|
||||
splashColor: Colors.transparent,
|
||||
highlightColor: Colors.transparent,
|
||||
onTap: onIncrement,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: ColorsManager.greyColor,
|
||||
size: 28,
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: InkWell(
|
||||
splashColor: Colors.transparent,
|
||||
highlightColor: Colors.transparent,
|
||||
onTap: onIncrement,
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Icon(
|
||||
Icons.add,
|
||||
color: ColorsManager.greyColor,
|
||||
size: 28,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -13,38 +13,36 @@ class PresenceDisplayValue extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DeviceControlsContainer(
|
||||
child: Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
||||
color: ColorsManager.dialogBlueTitle,
|
||||
fontSize: 40,
|
||||
fontWeight: FontWeight.w700),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodyLarge!.copyWith(
|
||||
color: ColorsManager.dialogBlueTitle,
|
||||
fontSize: 40,
|
||||
fontWeight: FontWeight.w700),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Text(
|
||||
postfix,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontSize: 16, fontWeight: FontWeight.w700),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Text(
|
||||
postfix,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontSize: 16, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
description,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
description,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -11,23 +11,21 @@ class PresenceStaticWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DeviceControlsContainer(
|
||||
child: Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
icon,
|
||||
width: 60,
|
||||
height: 60,
|
||||
),
|
||||
Text(
|
||||
description,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
icon,
|
||||
width: 60,
|
||||
height: 60,
|
||||
),
|
||||
Text(
|
||||
description,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -15,37 +15,35 @@ class PresenceState extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DeviceControlsContainer(
|
||||
child: Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Status:',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
SvgPicture.asset(
|
||||
value.toLowerCase() == 'motion'
|
||||
? Assets.sensorMotionIcon
|
||||
: value.toLowerCase() == 'presence'
|
||||
? Assets.sensorPresenceIcon
|
||||
: Assets.sensorVacantIcon,
|
||||
width: 60,
|
||||
height: 60,
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Status:',
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
SvgPicture.asset(
|
||||
value.toLowerCase() == 'motion'
|
||||
? Assets.sensorMotionIcon
|
||||
: value.toLowerCase() == 'presence'
|
||||
? Assets.sensorPresenceIcon
|
||||
: Assets.sensorVacantIcon,
|
||||
width: 60,
|
||||
height: 60,
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -56,38 +56,36 @@ class _CurrentTempState extends State<PresenceUpdateData> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DeviceControlsContainer(
|
||||
child: Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.title,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 10),
|
||||
),
|
||||
IncrementDecrementWidget(
|
||||
value: widget.value.toString(),
|
||||
description: widget.description ?? '',
|
||||
descriptionColor: ColorsManager.blackColor,
|
||||
onIncrement: () {
|
||||
if (_adjustedValue < widget.maxValue) {
|
||||
setState(() {
|
||||
_adjustedValue = _adjustedValue + widget.steps;
|
||||
});
|
||||
_onValueChanged(_adjustedValue);
|
||||
}
|
||||
},
|
||||
onDecrement: () {
|
||||
if (_adjustedValue > widget.minValue) {
|
||||
setState(() {
|
||||
_adjustedValue = _adjustedValue - widget.steps;
|
||||
});
|
||||
_onValueChanged(_adjustedValue);
|
||||
}
|
||||
}),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.title,
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.blackColor, fontWeight: FontWeight.w400, fontSize: 10),
|
||||
),
|
||||
IncrementDecrementWidget(
|
||||
value: widget.value.toString(),
|
||||
description: widget.description ?? '',
|
||||
descriptionColor: ColorsManager.blackColor,
|
||||
onIncrement: () {
|
||||
if (_adjustedValue < widget.maxValue) {
|
||||
setState(() {
|
||||
_adjustedValue = _adjustedValue + widget.steps;
|
||||
});
|
||||
_onValueChanged(_adjustedValue);
|
||||
}
|
||||
},
|
||||
onDecrement: () {
|
||||
if (_adjustedValue > widget.minValue) {
|
||||
setState(() {
|
||||
_adjustedValue = _adjustedValue - widget.steps;
|
||||
});
|
||||
_onValueChanged(_adjustedValue);
|
||||
}
|
||||
}),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -29,7 +29,8 @@ abstract class ApiEndpoints {
|
||||
////// Devices Management ////////////////
|
||||
|
||||
static const String getAllDevices = '$baseUrl/device';
|
||||
static const String getDeviceStatus = '$baseUrl/device/{uuid}/functions/status';
|
||||
static const String getDeviceStatus =
|
||||
'$baseUrl/device/{uuid}/functions/status';
|
||||
|
||||
static const String deviceControl = '$baseUrl/device/{uuid}/control';
|
||||
}
|
||||
|
Reference in New Issue
Block a user