mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-26 03:37:55 +00:00
Implemented Acs functions and fixed design issue
This commit is contained in:
@@ -10,12 +10,13 @@ import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
final String acId;
|
||||
late DeviceModel deviceModel;
|
||||
late AcStatusModel deviceStatus;
|
||||
|
||||
ACsBloc({required this.acId}) : super(AcsInitialState()) {
|
||||
on<AcsInitial>(_fetchAcsStatus);
|
||||
on<IncreaseCoolToTemp>(_increaseCoolTo);
|
||||
on<DecreaseCoolToTemp>(_decreaseCoolTo);
|
||||
on<SetCurrentTemp>(_setCurrentTemperature);
|
||||
on<ChangeLock>(_changeLockValue);
|
||||
on<ChangeAcMode>(_changeAcMode);
|
||||
on<ChangeFanSpeed>(_changeFanSpeed);
|
||||
}
|
||||
@@ -28,7 +29,7 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
for (var status in response['status']) {
|
||||
statusModelList.add(StatusModel.fromJson(status));
|
||||
}
|
||||
AcStatusModel deviceStatus = AcStatusModel.fromJson(statusModelList);
|
||||
deviceStatus = AcStatusModel.fromJson(statusModelList);
|
||||
emit(GetAcStatusState(acStatusModel: deviceStatus));
|
||||
} catch (e) {
|
||||
emit(AcsFailedState(error: e.toString()));
|
||||
@@ -36,82 +37,82 @@ class ACsBloc extends Bloc<AcsEvent, AcsState> {
|
||||
}
|
||||
}
|
||||
|
||||
void _setCurrentTemperature(SetCurrentTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
int value = (event.value * 10).toInt();
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_current', value: value), acId);
|
||||
void _changeLockValue(ChangeLock event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
// emit(AcIncreaseCoolTo(tempValue: tempValue));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
// emit(AcIncreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
final lockValue = !event.lockBool;
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'child_lock', value: lockValue), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.childLock = lockValue;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _increaseCoolTo(IncreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
double tempValue = event.value + 0.5;
|
||||
int value = (tempValue * 10).toInt();
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(AcIncreaseCoolTo(tempValue: tempValue));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
emit(AcIncreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.tempSet = value;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
|
||||
double tempValue = event.value - 0.5;
|
||||
int value = (tempValue * 10).toInt();
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
try {
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(AcDecreaseCoolTo(tempValue: tempValue));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
emit(AcDecreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.tempSet = value;
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeAcMode(ChangeAcMode event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
|
||||
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);
|
||||
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'mode', value: getACModeString(tempMode)), acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(AcModeState(tempModes: tempMode));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
// emit(AcDecreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.modeString = getACModeString(tempMode);
|
||||
deviceStatus.acMode = AcStatusModel.getACMode(getACModeString(tempMode));
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
void _changeFanSpeed(ChangeFanSpeed event, Emitter<AcsState> emit) async {
|
||||
emit(AcChangeTempLoading());
|
||||
emit(AcChangeLoading(acStatusModel: deviceStatus));
|
||||
|
||||
final fanSpeed = event.fanSpeeds;
|
||||
final response = await DevicesAPI.controlDevice(
|
||||
DeviceControlModel(deviceId: acId, code: 'level', value: getNextFanSpeedKey(fanSpeed)),
|
||||
acId);
|
||||
|
||||
if (response['success'] ?? false) {
|
||||
emit(FanSpeedState(fanSpeeds: fanSpeed));
|
||||
} else {
|
||||
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
|
||||
// emit(AcDecreaseCoolTo(tempValue: event.value));
|
||||
}
|
||||
try {
|
||||
if (response['success'] ?? false) {
|
||||
deviceStatus.fanSpeedsString = getNextFanSpeedKey(fanSpeed);
|
||||
deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed));
|
||||
}
|
||||
} catch (_) {}
|
||||
emit(AcModifyingState(acStatusModel: deviceStatus));
|
||||
}
|
||||
|
||||
String getACModeString(TempModes value) {
|
||||
|
||||
@@ -30,14 +30,6 @@ class DecreaseCoolToTemp extends AcsEvent {
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class SetCurrentTemp extends AcsEvent {
|
||||
final double value;
|
||||
const SetCurrentTemp({required this.value});
|
||||
|
||||
@override
|
||||
List<Object> get props => [value];
|
||||
}
|
||||
|
||||
class ChangeAcMode extends AcsEvent {
|
||||
final TempModes tempModes;
|
||||
const ChangeAcMode({required this.tempModes});
|
||||
@@ -53,3 +45,11 @@ class ChangeFanSpeed extends AcsEvent {
|
||||
@override
|
||||
List<Object> get props => [fanSpeeds];
|
||||
}
|
||||
|
||||
class ChangeLock extends AcsEvent {
|
||||
final bool lockBool;
|
||||
const ChangeLock({required this.lockBool});
|
||||
|
||||
@override
|
||||
List<Object> get props => [lockBool];
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_app/features/devices/model/status_model.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
|
||||
abstract class AcsState extends Equatable {
|
||||
const AcsState();
|
||||
@@ -13,30 +12,20 @@ class AcsInitialState extends AcsState {}
|
||||
|
||||
class AcsLoadingState extends AcsState {}
|
||||
|
||||
class AcChangeTempLoading extends AcsState {}
|
||||
|
||||
class AcChangeCurrentTempState extends AcsState {
|
||||
final double currentValue;
|
||||
const AcChangeCurrentTempState({required this.currentValue});
|
||||
class AcChangeLoading extends AcsState {
|
||||
final AcStatusModel acStatusModel;
|
||||
const AcChangeLoading({required this.acStatusModel});
|
||||
|
||||
@override
|
||||
List<Object> get props => [currentValue];
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class AcIncreaseCoolTo extends AcsState {
|
||||
final double tempValue;
|
||||
const AcIncreaseCoolTo({required this.tempValue});
|
||||
class AcModifyingState extends AcsState {
|
||||
final AcStatusModel acStatusModel;
|
||||
const AcModifyingState({required this.acStatusModel});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempValue];
|
||||
}
|
||||
|
||||
class AcDecreaseCoolTo extends AcsState {
|
||||
final double tempValue;
|
||||
const AcDecreaseCoolTo({required this.tempValue});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempValue];
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class GetAcStatusState extends AcsState {
|
||||
@@ -47,24 +36,9 @@ class GetAcStatusState extends AcsState {
|
||||
List<Object> get props => [acStatusModel];
|
||||
}
|
||||
|
||||
class AcModeState extends AcsState {
|
||||
final TempModes tempModes;
|
||||
const AcModeState({required this.tempModes});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tempModes];
|
||||
}
|
||||
|
||||
class FanSpeedState extends AcsState {
|
||||
final FanSpeeds fanSpeeds;
|
||||
const FanSpeedState({required this.fanSpeeds});
|
||||
|
||||
@override
|
||||
List<Object> get props => [fanSpeeds];
|
||||
}
|
||||
|
||||
class AcsFailedState extends AcsState {
|
||||
final String error;
|
||||
|
||||
const AcsFailedState({required this.error});
|
||||
|
||||
@override
|
||||
|
||||
@@ -52,7 +52,7 @@ class AcStatusModel {
|
||||
childLock: _childLock);
|
||||
}
|
||||
|
||||
TempModes getACMode(String value) {
|
||||
static TempModes getACMode(String value) {
|
||||
if (value == 'cold') {
|
||||
return TempModes.cold;
|
||||
} else if (value == 'hot') {
|
||||
@@ -64,7 +64,7 @@ class AcStatusModel {
|
||||
}
|
||||
}
|
||||
|
||||
FanSpeeds getFanSpeed(String value) {
|
||||
static FanSpeeds getFanSpeed(String value) {
|
||||
if (value == 'low') {
|
||||
return FanSpeeds.low;
|
||||
} else if (value == 'middle') {
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface_controls.dart';
|
||||
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface_temp_unit.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/font_manager.dart';
|
||||
|
||||
class AcInterface extends StatelessWidget {
|
||||
const AcInterface({super.key, required this.ac});
|
||||
@@ -49,37 +44,30 @@ class AcInterface extends StatelessWidget {
|
||||
opacity: 0.4,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: Constants.appBarHeight,
|
||||
left: Constants.defaultPadding,
|
||||
right: Constants.defaultPadding,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 380,
|
||||
),
|
||||
child: AcInterfaceTempUnit(
|
||||
acDevice: ac,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 380,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
child: AcInterfaceTempUnit(
|
||||
acDevice: ac,
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 130,
|
||||
),
|
||||
child: AcInterfaceControls(
|
||||
deviceModel: ac,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 130,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: AcInterfaceControls(
|
||||
deviceModel: ac,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_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';
|
||||
@@ -21,6 +21,25 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
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;
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
ACModeControlUnit(acDevice: deviceModel),
|
||||
@@ -28,7 +47,7 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: InkWell(
|
||||
child: GestureDetector(
|
||||
onTap: () {},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
@@ -40,12 +59,14 @@ class AcInterfaceControls extends StatelessWidget {
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
BlocProvider.of<ACsBloc>(context).add(ChangeLock(lockBool: lockValue));
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: SvgPicture.asset(Assets.assetsIconsLock),
|
||||
child: SvgPicture.asset(lockIconName),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'package:sleek_circular_slider/sleek_circular_slider.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
@@ -27,7 +26,6 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<ACsBloc, AcsState>(
|
||||
builder: (context, state) {
|
||||
// double setToTemp = 250;
|
||||
return DefaultContainer(
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -54,8 +52,14 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
fontWeight: FontsManager.regular,
|
||||
),
|
||||
modifier: (double value) {
|
||||
// return '${DeviceModel.temperature.toStringAsFixed(1)}°C';
|
||||
return '${value.toStringAsFixed(1)}°C';
|
||||
double temp = state is GetAcStatusState
|
||||
? state.acStatusModel.currentTemp / 10
|
||||
: state is AcModifyingState
|
||||
? state.acStatusModel.currentTemp / 10
|
||||
: state is AcChangeLoading
|
||||
? state.acStatusModel.currentTemp / 10
|
||||
: 25;
|
||||
return '$temp°C';
|
||||
},
|
||||
mainLabelStyle: context.titleLarge.copyWith(
|
||||
height: 0,
|
||||
@@ -72,24 +76,15 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
// min: DeviceModel.bounds.min,
|
||||
// max: DeviceModel.bounds.max,
|
||||
min: 20,
|
||||
max: 30,
|
||||
initialValue:
|
||||
state is GetAcStatusState ? state.acStatusModel.currentTemp / 10 : 25,
|
||||
onChange: (value) async {
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
// String valueAsString = value.toStringAsFixed(1);
|
||||
// if (valueAsString.endsWith(".0") || valueAsString.endsWith(".5")) {
|
||||
// value = double.parse(valueAsString);
|
||||
BlocProvider.of<ACsBloc>(context).add(SetCurrentTemp(value: value));
|
||||
// await DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid, code: 'temp_set', value: value * 10),
|
||||
// acDevice.uuid!);
|
||||
// }
|
||||
},
|
||||
initialValue: state is GetAcStatusState
|
||||
? state.acStatusModel.tempSet / 10
|
||||
: state is AcModifyingState
|
||||
? state.acStatusModel.tempSet / 10
|
||||
: state is AcChangeLoading
|
||||
? state.acStatusModel.tempSet / 10
|
||||
: 25,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -102,37 +97,21 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (state is AcChangeTempLoading) {
|
||||
if (state is AcChangeLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
double tempValue = 0;
|
||||
if (state is AcIncreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
if (state is AcModifyingState) {
|
||||
tempValue = state.acStatusModel.tempSet / 10;
|
||||
} else if (state is GetAcStatusState) {
|
||||
tempValue = state.acStatusModel.tempSet / 10;
|
||||
} else if (state is AcDecreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
}
|
||||
|
||||
if (tempValue > 20) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(DecreaseCoolToTemp(value: tempValue));
|
||||
}
|
||||
//TODO refactor the loading check
|
||||
// if (state is AcsLoadingState ||
|
||||
// state is DeviceControlSuccess ||
|
||||
// state is DeviceControlLoading) {
|
||||
// return;
|
||||
// }
|
||||
// if (setToTemp > 20) {
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'temp_set',
|
||||
// value: (setToTemp - 0.5) * 10),
|
||||
// acDevice.uuid!);
|
||||
// }
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsMinus,
|
||||
@@ -143,11 +122,11 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
children: [
|
||||
BodyLarge(
|
||||
// text: "${DeviceModel.coolTo}° C",
|
||||
text: state is AcIncreaseCoolTo
|
||||
? '${state.tempValue}° C'
|
||||
: state is AcDecreaseCoolTo
|
||||
? '${state.tempValue}° C'
|
||||
: state is GetAcStatusState
|
||||
text: state is GetAcStatusState
|
||||
? '${state.acStatusModel.tempSet / 10}° C'
|
||||
: state is AcModifyingState
|
||||
? '${state.acStatusModel.tempSet / 10}° C'
|
||||
: state is AcChangeLoading
|
||||
? '${state.acStatusModel.tempSet / 10}° C'
|
||||
: '',
|
||||
style: context.bodyLarge.copyWith(
|
||||
@@ -168,36 +147,22 @@ class AcInterfaceTempUnit extends StatelessWidget {
|
||||
dimension: 24,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (state is AcChangeTempLoading) {
|
||||
if (state is AcChangeLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
double tempValue = 0;
|
||||
if (state is AcIncreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
if (state is AcModifyingState) {
|
||||
tempValue = state.acStatusModel.tempSet / 10;
|
||||
} else if (state is GetAcStatusState) {
|
||||
tempValue = state.acStatusModel.tempSet / 10;
|
||||
} else if (state is AcDecreaseCoolTo) {
|
||||
tempValue = state.tempValue;
|
||||
} else if (state is AcChangeLoading) {
|
||||
tempValue = state.acStatusModel.tempSet / 10;
|
||||
}
|
||||
|
||||
if (tempValue < 30) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(IncreaseCoolToTemp(value: tempValue));
|
||||
}
|
||||
// if (state is GetDeviceStatusLoading ||
|
||||
// state is DeviceControlSuccess ||
|
||||
// state is DeviceControlLoading) {
|
||||
// return;
|
||||
// }
|
||||
// if (setToTemp < 30) {
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'temp_set',
|
||||
// value: (setToTemp + 0.5) * 10),
|
||||
// acDevice.uuid!);
|
||||
// }
|
||||
},
|
||||
child: SvgPicture.asset(
|
||||
Assets.assetsIconsPlus,
|
||||
|
||||
@@ -4,8 +4,6 @@ import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
@@ -27,63 +25,52 @@ class ACModeControlUnit extends StatelessWidget {
|
||||
return Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: InkWell(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
// print(
|
||||
// '\n\ncurrentFanSpeed:$fanSpeed \nchanged to:\t${fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!}\nKey:\t\t\"${reversedFanSpeedsMap[fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!]!}\"');
|
||||
if (state is GetAcStatusState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
|
||||
} else if (state is FanSpeedState) {
|
||||
} else if (state is AcModifyingState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.fanSpeeds));
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
|
||||
}
|
||||
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'level',
|
||||
// value: reversedFanSpeedsMap[fanSpeed]!),
|
||||
// acDevice.uuid!);
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: state is GetAcStatusState
|
||||
? SvgPicture.asset(fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
|
||||
: state is FanSpeedState
|
||||
? SvgPicture.asset(fanSpeedsIconMap[state.fanSpeeds]!)
|
||||
: const CircularProgressIndicator()),
|
||||
: state is AcModifyingState
|
||||
? SvgPicture.asset(fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
|
||||
: state is AcChangeLoading
|
||||
? SvgPicture.asset(
|
||||
fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
|
||||
: const CircularProgressIndicator()),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Flexible(
|
||||
child: InkWell(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (state is GetAcStatusState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
|
||||
} else if (state is FanSpeedState) {
|
||||
} else if (state is AcModifyingState) {
|
||||
BlocProvider.of<ACsBloc>(context)
|
||||
.add(ChangeFanSpeed(fanSpeeds: state.fanSpeeds));
|
||||
.add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
|
||||
}
|
||||
// tempMode = tempModesMap[getNextItem(tempModesMap, tempMode)]!;
|
||||
// DevicesCubit.getInstance().deviceControl(
|
||||
// DeviceControlModel(
|
||||
// deviceId: acDevice.uuid,
|
||||
// code: 'mode',
|
||||
// value: reversedTempModesMap[tempMode]!),
|
||||
// acDevice.uuid!);
|
||||
},
|
||||
child: DefaultContainer(
|
||||
height: 55,
|
||||
child: Center(
|
||||
child: state is GetAcStatusState
|
||||
? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
|
||||
: state is AcModeState
|
||||
? SvgPicture.asset(tempModesIconMap[state.tempModes]!)
|
||||
: const CircularProgressIndicator(),
|
||||
: state is AcModifyingState
|
||||
? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
|
||||
: state is AcChangeLoading
|
||||
? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
|
||||
: const CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -3,13 +3,11 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
||||
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
||||
|
||||
import 'package:syncrow_app/generated/assets.dart';
|
||||
|
||||
class ACTempWidget extends StatelessWidget {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
|
||||
@@ -28,46 +27,40 @@ class ACsView extends StatelessWidget {
|
||||
// if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
|
||||
// selectedAC = DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
|
||||
// }
|
||||
return AnnotatedRegion(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
|
||||
statusBarIconBrightness: Brightness.light,
|
||||
return Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
// extendBodyBehindAppBar: true,
|
||||
// extendBody: true,
|
||||
appBar: CategoryViewAppBar(
|
||||
title: deviceModel?.name ?? '',
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
backgroundColor: ColorsManager.backgroundColor,
|
||||
extendBodyBehindAppBar: true,
|
||||
extendBody: true,
|
||||
appBar: CategoryViewAppBar(
|
||||
title: deviceModel?.name ?? '',
|
||||
body: SafeArea(
|
||||
child: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.assetsImagesBackground,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
opacity: 0.4,
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
width: MediaQuery.sizeOf(context).width,
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration: const BoxDecoration(
|
||||
image: DecorationImage(
|
||||
image: AssetImage(
|
||||
Assets.assetsImagesBackground,
|
||||
),
|
||||
fit: BoxFit.cover,
|
||||
opacity: 0.4,
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: Constants.appBarHeight,
|
||||
left: Constants.defaultPadding,
|
||||
right: Constants.defaultPadding,
|
||||
),
|
||||
child: state is AcsLoadingState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
: SizedBox.expand(
|
||||
child: deviceModel != null ? AcInterface(ac: deviceModel!) : ACsList(),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: Constants.defaultPadding,
|
||||
left: Constants.defaultPadding,
|
||||
right: Constants.defaultPadding,
|
||||
),
|
||||
child: state is AcsLoadingState
|
||||
? const Center(
|
||||
child: DefaultContainer(
|
||||
width: 50, height: 50, child: CircularProgressIndicator()),
|
||||
)
|
||||
: SizedBox.expand(
|
||||
child: deviceModel != null ? AcInterface(ac: deviceModel!) : ACsList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/// This widget displays the icon and name of the device, along with a switch
|
||||
/// to control its state. Tapping on the widget opens the device interface.
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
||||
@@ -16,6 +17,7 @@ import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_
|
||||
import 'package:syncrow_app/features/shared_widgets/custom_switch.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/navigation/navigation_service.dart';
|
||||
import 'package:syncrow_app/utils/context_extension.dart';
|
||||
import 'package:syncrow_app/utils/helpers/custom_page_route.dart';
|
||||
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
||||
@@ -82,7 +84,11 @@ class RoomPageSwitch extends StatelessWidget {
|
||||
void showDeviceInterface(DeviceModel device, BuildContext context) {
|
||||
switch (device.productType) {
|
||||
case DeviceType.AC:
|
||||
navigateToInterface(ACsView(deviceModel: device), context);
|
||||
Navigator.push(
|
||||
context,
|
||||
PageRouteBuilder(
|
||||
pageBuilder: (context, animation1, animation2) => ACsView(deviceModel: device)));
|
||||
// navigateToInterface(ACsView(deviceModel: device), context);
|
||||
break;
|
||||
case DeviceType.WallSensor:
|
||||
navigateToInterface(WallMountedInterface(wallSensor: device), context);
|
||||
|
||||
Reference in New Issue
Block a user