Implemented Ac functionality, and bug fixes

This commit is contained in:
Abdullah Alassaf
2024-05-20 02:40:50 +03:00
parent 0f75c3def1
commit 4257d69768
27 changed files with 733 additions and 451 deletions

105
.vscode/launch.json vendored
View File

@ -1,60 +1,61 @@
{ {
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [ "configurations": [
// {
// "name": "Iphone 15 Pro Max",
// "request": "launch",
// "type": "dart",
// "deviceId": "0147FC23-3D6C-406A-BE2C-9E67BAF3DA9B"
// },
// {
// "name": "Faris Iphone ",
// "request": "launch",
// "type": "dart",
// "deviceId": "00008101-00050C1C02FA001E"
// },
// {
// "name": "Iphone 15 Pro",
// "request": "launch",
// "type": "dart",
// "deviceId": "B26AF31B-D38E-4485-9628-528E0DB29789"
// },
// {
// "name": "Iphone SE",
// "request": "launch",
// "type": "dart",
// "deviceId": "A0274205-52D6-48CC-8344-AB4AE3082DE4",
// },
{ {
"name": "syncrow-app",
"request": "launch", "name": "DEVELOPMENT",
"type": "dart"
},
{
"name": "syncrow-app (profile mode)",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
"flutterMode": "profile"
}, "args": [
{
"name": "syncrow-app (release mode)", "--dart-define",
"FLAVOR=development"
],
"flutterMode": "debug"
},{
"name": "STAGING",
"request": "launch", "request": "launch",
"type": "dart", "type": "dart",
"flutterMode": "release"
} "args": [
],
// "compounds": [ "--dart-define",
// {
// "name": "All Device", "FLAVOR=staging"
// "configurations": [
// "Iphone 15 Pro Max", ],
// "Iphone SE"
// ] "flutterMode": "debug"
// }
// ] },{
"name": "PRODUCTION",
"request": "launch",
"type": "dart",
"args": [
"--dart-define",
"FLAVOR=production"
],
"flutterMode": "debug"
},
]
} }

View File

@ -153,7 +153,7 @@ class HomeCubit extends Cubit<HomeState> {
emitSafe(GetSpaceRoomsError(failure.toString())); emitSafe(GetSpaceRoomsError(failure.toString()));
return; return;
} }
if (space.rooms != null) { if (space.rooms != null && space.rooms!.isNotEmpty) {
emitSafe(GetSpaceRoomsSuccess(space.rooms!)); emitSafe(GetSpaceRoomsSuccess(space.rooms!));
} else { } else {
emitSafe(GetSpaceRoomsError("No rooms found")); emitSafe(GetSpaceRoomsError("No rooms found"));

View File

@ -0,0 +1,128 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/services/api/devices_api.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class ACsBloc extends Bloc<AcsEvent, AcsState> {
final String acId;
late DeviceModel deviceModel;
ACsBloc({required this.acId}) : super(AcsInitialState()) {
on<AcsInitial>(_fetchAcsStatus);
on<IncreaseCoolToTemp>(_increaseCoolTo);
on<DecreaseCoolToTemp>(_decreaseCoolTo);
on<SetCurrentTemp>(_setCurrentTemperature);
on<ChangeAcMode>(_changeAcMode);
on<ChangeFanSpeed>(_changeFanSpeed);
}
void _fetchAcsStatus(AcsInitial event, Emitter<AcsState> emit) async {
emit(AcsLoadingState());
try {
var response = await DevicesAPI.getDeviceStatus(acId);
List<StatusModel> statusModelList = [];
for (var status in response['status']) {
statusModelList.add(StatusModel.fromJson(status));
}
AcStatusModel deviceStatus = AcStatusModel.fromJson(statusModelList);
emit(GetAcStatusState(acStatusModel: deviceStatus));
} catch (e) {
emit(AcsFailedState(error: e.toString()));
return;
}
}
void _setCurrentTemperature(SetCurrentTemp event, Emitter<AcsState> emit) async {
emit(AcChangeTempLoading());
int value = (event.value * 10).toInt();
final response = await DevicesAPI.controlDevice(
DeviceControlModel(deviceId: acId, code: 'temp_current', value: value), acId);
if (response['success'] ?? false) {
// emit(AcIncreaseCoolTo(tempValue: tempValue));
} else {
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
// emit(AcIncreaseCoolTo(tempValue: event.value));
}
}
void _increaseCoolTo(IncreaseCoolToTemp event, Emitter<AcsState> emit) async {
emit(AcChangeTempLoading());
double tempValue = event.value + 0.5;
int value = (tempValue * 10).toInt();
final response = await DevicesAPI.controlDevice(
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
if (response['success'] ?? false) {
emit(AcIncreaseCoolTo(tempValue: tempValue));
} else {
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
emit(AcIncreaseCoolTo(tempValue: event.value));
}
}
void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter<AcsState> emit) async {
emit(AcChangeTempLoading());
double tempValue = event.value - 0.5;
int value = (tempValue * 10).toInt();
final response = await DevicesAPI.controlDevice(
DeviceControlModel(deviceId: acId, code: 'temp_set', value: value), acId);
if (response['success'] ?? false) {
emit(AcDecreaseCoolTo(tempValue: tempValue));
} else {
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
emit(AcDecreaseCoolTo(tempValue: event.value));
}
}
void _changeAcMode(ChangeAcMode event, Emitter<AcsState> emit) async {
emit(AcChangeTempLoading());
final tempMode = tempModesMap[getNextItem(tempModesMap, event.tempModes)]!;
final response = await DevicesAPI.controlDevice(
DeviceControlModel(deviceId: acId, code: 'mode', value: getACModeString(tempMode)), acId);
if (response['success'] ?? false) {
emit(AcModeState(tempModes: tempMode));
} else {
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
// emit(AcDecreaseCoolTo(tempValue: event.value));
}
}
void _changeFanSpeed(ChangeFanSpeed event, Emitter<AcsState> emit) async {
emit(AcChangeTempLoading());
final fanSpeed = event.fanSpeeds;
final response = await DevicesAPI.controlDevice(
DeviceControlModel(deviceId: acId, code: 'level', value: getNextFanSpeedKey(fanSpeed)),
acId);
if (response['success'] ?? false) {
emit(FanSpeedState(fanSpeeds: fanSpeed));
} else {
emit(const AcsFailedState(error: 'Cannot change the device temperature'));
// emit(AcDecreaseCoolTo(tempValue: event.value));
}
}
String getACModeString(TempModes value) {
if (value == TempModes.cold) {
return 'cold';
} else if (value == TempModes.hot) {
return 'hot';
} else if (value == TempModes.wind) {
return 'wind';
} else {
return 'cold';
}
}
}

View File

@ -0,0 +1,55 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
abstract class AcsEvent extends Equatable {
const AcsEvent();
@override
List<Object> get props => [];
}
class AcsLoading extends AcsEvent {}
class AcsInitial extends AcsEvent {}
class ACsChangeStatus extends AcsEvent {}
class IncreaseCoolToTemp extends AcsEvent {
final double value;
const IncreaseCoolToTemp({required this.value});
@override
List<Object> get props => [value];
}
class DecreaseCoolToTemp extends AcsEvent {
final double value;
const DecreaseCoolToTemp({required this.value});
@override
List<Object> get props => [value];
}
class SetCurrentTemp extends AcsEvent {
final double value;
const SetCurrentTemp({required this.value});
@override
List<Object> get props => [value];
}
class ChangeAcMode extends AcsEvent {
final TempModes tempModes;
const ChangeAcMode({required this.tempModes});
@override
List<Object> get props => [tempModes];
}
class ChangeFanSpeed extends AcsEvent {
final FanSpeeds fanSpeeds;
const ChangeFanSpeed({required this.fanSpeeds});
@override
List<Object> get props => [fanSpeeds];
}

View File

@ -0,0 +1,72 @@
import 'package:equatable/equatable.dart';
import 'package:syncrow_app/features/devices/model/status_model.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart';
abstract class AcsState extends Equatable {
const AcsState();
@override
List<Object> get props => [];
}
class AcsInitialState extends AcsState {}
class AcsLoadingState extends AcsState {}
class AcChangeTempLoading extends AcsState {}
class AcChangeCurrentTempState extends AcsState {
final double currentValue;
const AcChangeCurrentTempState({required this.currentValue});
@override
List<Object> get props => [currentValue];
}
class AcIncreaseCoolTo extends AcsState {
final double tempValue;
const AcIncreaseCoolTo({required this.tempValue});
@override
List<Object> get props => [tempValue];
}
class AcDecreaseCoolTo extends AcsState {
final double tempValue;
const AcDecreaseCoolTo({required this.tempValue});
@override
List<Object> get props => [tempValue];
}
class GetAcStatusState extends AcsState {
final AcStatusModel acStatusModel;
const GetAcStatusState({required this.acStatusModel});
@override
List<Object> get props => [acStatusModel];
}
class AcModeState extends AcsState {
final TempModes tempModes;
const AcModeState({required this.tempModes});
@override
List<Object> get props => [tempModes];
}
class FanSpeedState extends AcsState {
final FanSpeeds fanSpeeds;
const FanSpeedState({required this.fanSpeeds});
@override
List<Object> get props => [fanSpeeds];
}
class AcsFailedState extends AcsState {
final String error;
const AcsFailedState({required this.error});
@override
List<Object> get props => [error];
}

View File

@ -1,51 +0,0 @@
// import 'package:bloc/bloc.dart';
// import 'package:flutter/foundation.dart';
// import 'package:meta/meta.dart';
// import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
// import 'package:syncrow_app/features/devices/model/device_category_model.dart';
// import 'package:syncrow_app/features/devices/model/device_model.dart';
// part 'ac_state.dart';
// class AcCubit extends Cubit<AcState> {
// AcCubit() : super(AcInitial());
// DeviceModel? getSelectedAC() {
// DevicesCategoryModel category = DevicesCubit.allCategories![0];
// for (var device in category.devices) {
// if (device is && device.isSelected) {
// return device;
// }
// }
// return null;
// }
// void setTempToAll(double temperature) {
// for (DeviceModel ac in category.devices) {
// if (ac is DeviceModel) {
// if (ac.temperature != temperature &&
// ac.bounds.min <= temperature &&
// temperature <= ac.bounds.max) {
// setACTemp(ac, temperature);
// }
// }
// }
// universalACTemp = temperature;
// emit(ACsTempChanged(temperature));
// }
// void setACTemp(DeviceModel model, double temp) {
// if (model.bounds.min <= temp && temp <= model.bounds.max) {
// model.temperature = temp;
// }
// emit(ACsTempChanged(temp));
// }
// double getTemp(int index) {
// var device = category.devices[index];
// if (device is DeviceModel) {
// return device.temperature;
// }
// return 0.0; // or any default value you prefer
// }
// }

View File

@ -1,6 +0,0 @@
// part of 'ac_cubit.dart';
// @immutable
// sealed class AcState {}
// final class AcInitial extends AcState {}

View File

@ -19,7 +19,6 @@ import 'package:syncrow_app/services/api/devices_api.dart';
import 'package:syncrow_app/services/api/network_exception.dart'; import 'package:syncrow_app/services/api/network_exception.dart';
import 'package:syncrow_app/services/api/spaces_api.dart'; import 'package:syncrow_app/services/api/spaces_api.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart';
part 'devices_state.dart'; part 'devices_state.dart';
class DevicesCubit extends Cubit<DevicesState> { class DevicesCubit extends Cubit<DevicesState> {
@ -37,8 +36,6 @@ class DevicesCubit extends Cubit<DevicesState> {
return _instance ??= DevicesCubit._(); return _instance ??= DevicesCubit._();
} }
DeviceModel? selectedDevice;
@override @override
Future<void> close() { Future<void> close() {
_instance = null; _instance = null;
@ -100,14 +97,14 @@ class DevicesCubit extends Cubit<DevicesState> {
return null; return null;
} }
DevicesCategoryModel? get chosenCategory { // DevicesCategoryModel? get chosenCategory {
for (var category in allCategories!) { // for (var category in allCategories!) {
if (category.isSelected) { // if (category.isSelected) {
return category; // return category;
} // }
} // }
return null; // return null;
} // }
selectDevice(DeviceModel device) { selectDevice(DeviceModel device) {
for (var category in allCategories!) { for (var category in allCategories!) {
@ -251,7 +248,7 @@ class DevicesCubit extends Cubit<DevicesState> {
code: control.code, code: control.code,
)); ));
try { try {
var response = await DevicesAPI.controlDevice(control); var response = await DevicesAPI.controlDevice(control, deviceId);
if (response['success'] ?? false) { if (response['success'] ?? false) {
emitSafe(DeviceControlSuccess(code: control.code)); emitSafe(DeviceControlSuccess(code: control.code));
@ -306,12 +303,12 @@ class DevicesCubit extends Cubit<DevicesState> {
//get status for each device //get status for each device
//TODO get devices status per page via page controller instead of getting all devices status at once //TODO get devices status per page via page controller instead of getting all devices status at once
List<DeviceModel> devices = HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!; // List<DeviceModel> devices = HomeCubit.getInstance().selectedSpace!.rooms![roomIndex].devices!;
if (devices.isNotEmpty) { // if (devices.isNotEmpty) {
for (var device in devices) { // for (var device in devices) {
fetchDevicesStatues(device.uuid!, roomIndex); // fetchDevicesStatues(device.uuid!, roomIndex);
} // }
} // }
} }
fetchDevicesStatues(String deviceUuid, int roomIndex, {String? code}) async { fetchDevicesStatues(String deviceUuid, int roomIndex, {String? code}) async {

View File

@ -19,7 +19,7 @@ class DeviceControlModel {
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
return { return {
'deviceUuid': deviceId, // 'deviceUuid': deviceId,
'code': code, 'code': code,
'value': value, 'value': value,
}; };

View File

@ -1,3 +1,84 @@
import 'package:syncrow_app/utils/resource_manager/constants.dart';
class AcStatusModel {
bool acSwitch;
String modeString;
int tempSet;
int currentTemp;
String fanSpeedsString;
bool childLock;
late TempModes acMode;
late FanSpeeds acFanSpeed;
AcStatusModel(
{required this.acSwitch,
required this.modeString,
required this.tempSet,
required this.currentTemp,
required this.fanSpeedsString,
required this.childLock}) {
acMode = getACMode(modeString);
acFanSpeed = getFanSpeed(fanSpeedsString);
}
factory AcStatusModel.fromJson(List<StatusModel> jsonList) {
late bool _acSwitch;
late String _mode;
late int _tempSet;
late int _currentTemp;
late String _fanSpeeds;
late bool _childLock;
for (int i = 0; i < jsonList.length; i++) {
if (jsonList[i].code == 'switch') {
_acSwitch = jsonList[i].value ?? false;
} else if (jsonList[i].code == 'mode') {
_mode = jsonList[i].value ?? TempModes.cold;
} else if (jsonList[i].code == 'temp_set') {
_tempSet = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'temp_current') {
_currentTemp = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'level') {
_fanSpeeds = jsonList[i].value ?? 210;
} else if (jsonList[i].code == 'child_lock') {
_childLock = jsonList[i].value ?? false;
}
}
return AcStatusModel(
acSwitch: _acSwitch,
modeString: _mode,
tempSet: _tempSet,
currentTemp: _currentTemp,
fanSpeedsString: _fanSpeeds,
childLock: _childLock);
}
TempModes getACMode(String value) {
if (value == 'cold') {
return TempModes.cold;
} else if (value == 'hot') {
return TempModes.hot;
} else if (value == 'wind') {
return TempModes.wind;
} else {
return TempModes.cold;
}
}
FanSpeeds getFanSpeed(String value) {
if (value == 'low') {
return FanSpeeds.low;
} else if (value == 'middle') {
return FanSpeeds.middle;
} else if (value == 'high') {
return FanSpeeds.high;
} else if (value == 'auto') {
return FanSpeeds.auto;
} else {
return FanSpeeds.auto;
}
}
}
class StatusModel { class StatusModel {
String? code; String? code;
dynamic value; dynamic value;

View File

@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.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/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_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_controls.dart';
@ -18,86 +20,71 @@ class AcInterface extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AnnotatedRegion( return BlocConsumer<ACsBloc, AcsState>(
value: SystemUiOverlayStyle( listener: (context, state) {
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5), if (state is AcsFailedState) {
statusBarIconBrightness: Brightness.light, ScaffoldMessenger.of(context).showSnackBar(
), SnackBar(
child: SafeArea( content: Text(state.error),
child: BlocConsumer<DevicesCubit, DevicesState>( ),
listener: (context, state) { );
if (state is DeviceControlError) { }
// ScaffoldMessenger.of(context).showSnackBar( },
// SnackBar( builder: (context, state) {
// content: Text(state.errorMsg), return
// ), // Scaffold(
// ); // backgroundColor: ColorsManager.backgroundColor,
} // extendBodyBehindAppBar: true,
}, // extendBody: true,
builder: (context, state) { // body:
return Scaffold( Container(
backgroundColor: ColorsManager.backgroundColor, width: MediaQuery.sizeOf(context).width,
extendBodyBehindAppBar: true, height: MediaQuery.sizeOf(context).height,
extendBody: true, decoration: const BoxDecoration(
appBar: AppBar( image: DecorationImage(
backgroundColor: Colors.transparent, image: AssetImage(
centerTitle: true, Assets.assetsImagesBackground,
title: BodyLarge(
text: ac.name ?? "",
fontColor: ColorsManager.primaryColor,
fontWeight: FontsManager.bold,
),
), ),
body: Container( fit: BoxFit.cover,
width: MediaQuery.sizeOf(context).width, opacity: 0.4,
height: MediaQuery.sizeOf(context).height, ),
decoration: const BoxDecoration( ),
image: DecorationImage( child: Padding(
image: AssetImage( padding: EdgeInsets.only(
Assets.assetsImagesBackground, top: Constants.appBarHeight,
left: Constants.defaultPadding,
right: Constants.defaultPadding,
),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 380,
), ),
fit: BoxFit.cover, child: AcInterfaceTempUnit(
opacity: 0.4, acDevice: ac,
),
),
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,
),
),
const SizedBox(
height: 10,
),
ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 130,
),
child: AcInterfaceControls(
deviceModel: ac,
),
),
],
), ),
), ),
), const SizedBox(
height: 10,
),
ConstrainedBox(
constraints: const BoxConstraints(
maxHeight: 130,
),
child: AcInterfaceControls(
deviceModel: ac,
),
),
],
), ),
); ),
}, ),
), );
), // );
},
); );
} }
} }

View File

@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.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/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_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_mode_control_unit.dart';
@ -17,7 +19,7 @@ class AcInterfaceControls extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<ACsBloc, AcsState>(
builder: (context, state) { builder: (context, state) {
return Column( return Column(
children: [ children: [
@ -31,8 +33,7 @@ class AcInterfaceControls extends StatelessWidget {
child: DefaultContainer( child: DefaultContainer(
height: 55, height: 55,
child: Center( child: Center(
child: child: SvgPicture.asset(Assets.assetsIconsAutomatedClock),
SvgPicture.asset(Assets.assetsIconsAutomatedClock),
), ),
), ),
), ),

View File

@ -2,8 +2,10 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:sleek_circular_slider/sleek_circular_slider.dart'; import 'package:sleek_circular_slider/sleek_circular_slider.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/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/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
@ -23,12 +25,9 @@ class AcInterfaceTempUnit extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<ACsBloc, AcsState>(
builder: (context, state) { builder: (context, state) {
double setToTemp = acDevice.status // double setToTemp = 250;
.firstWhere((element) => element.code == 'temp_set')
.value /
10;
return DefaultContainer( return DefaultContainer(
child: Column( child: Column(
children: [ children: [
@ -44,13 +43,11 @@ class AcInterfaceTempUnit extends StatelessWidget {
shadowWidth: 0, shadowWidth: 0,
), ),
customColors: CustomSliderColors( customColors: CustomSliderColors(
progressBarColor: progressBarColor: ColorsManager.primaryColor.withOpacity(.6),
ColorsManager.primaryColor.withOpacity(.6),
trackColor: ColorsManager.greyColor, trackColor: ColorsManager.greyColor,
dotColor: Colors.transparent, dotColor: Colors.transparent,
), ),
infoProperties: InfoProperties( infoProperties: InfoProperties(
//TODO: move to strings manager
bottomLabelText: 'CURRENT TEMP', bottomLabelText: 'CURRENT TEMP',
bottomLabelStyle: context.bodyLarge.copyWith( bottomLabelStyle: context.bodyLarge.copyWith(
color: Colors.grey, color: Colors.grey,
@ -79,23 +76,19 @@ class AcInterfaceTempUnit extends StatelessWidget {
// max: DeviceModel.bounds.max, // max: DeviceModel.bounds.max,
min: 20, min: 20,
max: 30, max: 30,
initialValue: acDevice.status initialValue:
.firstWhere( state is GetAcStatusState ? state.acStatusModel.currentTemp / 10 : 25,
(element) => element.code == 'temp_current') onChange: (value) async {
.value / await Future.delayed(const Duration(seconds: 2));
10, // String valueAsString = value.toStringAsFixed(1);
onChange: (value) { // if (valueAsString.endsWith(".0") || valueAsString.endsWith(".5")) {
String valueAsString = value.toStringAsFixed(1); // value = double.parse(valueAsString);
if (valueAsString.endsWith(".0") || BlocProvider.of<ACsBloc>(context).add(SetCurrentTemp(value: value));
valueAsString.endsWith(".5")) { // await DevicesCubit.getInstance().deviceControl(
value = double.parse(valueAsString); // DeviceControlModel(
DevicesCubit.getInstance().deviceControl( // deviceId: acDevice.uuid, code: 'temp_set', value: value * 10),
DeviceControlModel( // acDevice.uuid!);
deviceId: acDevice.uuid, // }
code: 'temp_set',
value: value * 10),
acDevice.uuid!);
}
}, },
), ),
), ),
@ -109,23 +102,37 @@ class AcInterfaceTempUnit extends StatelessWidget {
dimension: 24, dimension: 24,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
//TODO refactor the loading check if (state is AcChangeTempLoading) {
if (state is GetDeviceStatusLoading &&
state.code == 'temp_set' ||
state is DeviceControlSuccess &&
state.code == 'temp_set' ||
state is DeviceControlLoading &&
state.code == 'temp_set') {
return; return;
} }
if (setToTemp > 20) {
DevicesCubit.getInstance().deviceControl( double tempValue = 0;
DeviceControlModel( if (state is AcIncreaseCoolTo) {
deviceId: acDevice.uuid, tempValue = state.tempValue;
code: 'temp_set', } else if (state is GetAcStatusState) {
value: (setToTemp - 0.5) * 10), tempValue = state.acStatusModel.tempSet / 10;
acDevice.uuid!); } 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( child: SvgPicture.asset(
Assets.assetsIconsMinus, Assets.assetsIconsMinus,
@ -136,14 +143,15 @@ class AcInterfaceTempUnit extends StatelessWidget {
children: [ children: [
BodyLarge( BodyLarge(
// text: "${DeviceModel.coolTo}° C", // text: "${DeviceModel.coolTo}° C",
text: '$setToTemp° C', text: state is AcIncreaseCoolTo
? '${state.tempValue}° C'
: state is AcDecreaseCoolTo
? '${state.tempValue}° C'
: state is GetAcStatusState
? '${state.acStatusModel.tempSet / 10}° C'
: '',
style: context.bodyLarge.copyWith( style: context.bodyLarge.copyWith(
color: state is GetDeviceStatusLoading && color: state is AcsLoadingState
state.code == 'temp_set' ||
state is DeviceControlSuccess &&
state.code == 'temp_set' ||
state is DeviceControlLoading &&
state.code == 'temp_set'
? Colors.grey ? Colors.grey
: ColorsManager.primaryColor.withOpacity(0.6), : ColorsManager.primaryColor.withOpacity(0.6),
fontWeight: FontsManager.bold, fontWeight: FontsManager.bold,
@ -160,22 +168,36 @@ class AcInterfaceTempUnit extends StatelessWidget {
dimension: 24, dimension: 24,
child: InkWell( child: InkWell(
onTap: () { onTap: () {
if (state is GetDeviceStatusLoading && if (state is AcChangeTempLoading) {
state.code == 'temp_set' ||
state is DeviceControlSuccess &&
state.code == 'temp_set' ||
state is DeviceControlLoading &&
state.code == 'temp_set') {
return; return;
} }
if (setToTemp < 30) {
DevicesCubit.getInstance().deviceControl( double tempValue = 0;
DeviceControlModel( if (state is AcIncreaseCoolTo) {
deviceId: acDevice.uuid, tempValue = state.tempValue;
code: 'temp_set', } else if (state is GetAcStatusState) {
value: (setToTemp + 0.5) * 10), tempValue = state.acStatusModel.tempSet / 10;
acDevice.uuid!); } else if (state is AcDecreaseCoolTo) {
tempValue = state.tempValue;
} }
if (tempValue < 30) {
BlocProvider.of<ACsBloc>(context)
.add(IncreaseCoolToTemp(value: tempValue));
}
// if (state is GetDeviceStatusLoading ||
// state is DeviceControlSuccess ||
// state is DeviceControlLoading) {
// return;
// }
// if (setToTemp < 30) {
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: acDevice.uuid,
// code: 'temp_set',
// value: (setToTemp + 0.5) * 10),
// acDevice.uuid!);
// }
}, },
child: SvgPicture.asset( child: SvgPicture.asset(
Assets.assetsIconsPlus, Assets.assetsIconsPlus,

View File

@ -1,13 +1,16 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.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/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart';
class ACModeControlUnit extends StatefulWidget { class ACModeControlUnit extends StatelessWidget {
const ACModeControlUnit({ const ACModeControlUnit({
super.key, super.key,
required this.acDevice, required this.acDevice,
@ -15,21 +18,12 @@ class ACModeControlUnit extends StatefulWidget {
final DeviceModel acDevice; final DeviceModel acDevice;
@override
State<ACModeControlUnit> createState() => _ACModeControlUnitState();
}
class _ACModeControlUnitState extends State<ACModeControlUnit> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<ACsBloc, AcsState>(
builder: (context, state) { builder: (context, state) {
FanSpeeds fanSpeed = fanSpeedsMap[widget.acDevice.status // FanSpeeds fanSpeed = FanSpeeds.middle;
.firstWhere((element) => element.code == 'level') // TempModes tempMode = TempModes.cold;
.value]!;
TempModes tempMode = tempModesMap[widget.acDevice.status
.firstWhere((element) => element.code == 'mode')
.value]!;
return Row( return Row(
children: [ children: [
Flexible( Flexible(
@ -37,27 +31,29 @@ class _ACModeControlUnitState extends State<ACModeControlUnit> {
onTap: () { onTap: () {
// print( // print(
// '\n\ncurrentFanSpeed:$fanSpeed \nchanged to:\t${fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!}\nKey:\t\t\"${reversedFanSpeedsMap[fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!]!}\"'); // '\n\ncurrentFanSpeed:$fanSpeed \nchanged to:\t${fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!}\nKey:\t\t\"${reversedFanSpeedsMap[fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!]!}\"');
if (state is GetAcStatusState) {
BlocProvider.of<ACsBloc>(context)
.add(ChangeFanSpeed(fanSpeeds: state.acStatusModel.acFanSpeed));
} else if (state is FanSpeedState) {
BlocProvider.of<ACsBloc>(context)
.add(ChangeFanSpeed(fanSpeeds: state.fanSpeeds));
}
fanSpeed = fanSpeedsMap[getNextFanSpeedKey(fanSpeed)]!; // DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
DevicesCubit.getInstance().deviceControl( // deviceId: acDevice.uuid,
DeviceControlModel( // code: 'level',
deviceId: widget.acDevice.uuid, // value: reversedFanSpeedsMap[fanSpeed]!),
code: 'level', // acDevice.uuid!);
value: reversedFanSpeedsMap[fanSpeed]!),
widget.acDevice.uuid!);
}, },
child: DefaultContainer( child: DefaultContainer(
height: 55, height: 55,
child: Center( child: Center(
child: state is GetDeviceStatusLoading && child: state is GetAcStatusState
state.code == 'level' || ? SvgPicture.asset(fanSpeedsIconMap[state.acStatusModel.acFanSpeed]!)
state is DeviceControlSuccess && : state is FanSpeedState
state.code == 'level' || ? SvgPicture.asset(fanSpeedsIconMap[state.fanSpeeds]!)
state is DeviceControlLoading && : const CircularProgressIndicator()),
state.code == 'level'
? const CircularProgressIndicator()
: SvgPicture.asset(fanSpeedsIconMap[fanSpeed]!)),
), ),
), ),
), ),
@ -65,25 +61,29 @@ class _ACModeControlUnitState extends State<ACModeControlUnit> {
Flexible( Flexible(
child: InkWell( child: InkWell(
onTap: () { onTap: () {
tempMode = tempModesMap[getNextItem(tempModesMap, tempMode)]!; if (state is GetAcStatusState) {
DevicesCubit.getInstance().deviceControl( BlocProvider.of<ACsBloc>(context)
DeviceControlModel( .add(ChangeAcMode(tempModes: state.acStatusModel.acMode));
deviceId: widget.acDevice.uuid, } else if (state is FanSpeedState) {
code: 'mode', BlocProvider.of<ACsBloc>(context)
value: reversedTempModesMap[tempMode]!), .add(ChangeFanSpeed(fanSpeeds: state.fanSpeeds));
widget.acDevice.uuid!); }
// tempMode = tempModesMap[getNextItem(tempModesMap, tempMode)]!;
// DevicesCubit.getInstance().deviceControl(
// DeviceControlModel(
// deviceId: acDevice.uuid,
// code: 'mode',
// value: reversedTempModesMap[tempMode]!),
// acDevice.uuid!);
}, },
child: DefaultContainer( child: DefaultContainer(
height: 55, height: 55,
child: Center( child: Center(
child: state is GetDeviceStatusLoading && child: state is GetAcStatusState
state.code == 'mode' || ? SvgPicture.asset(tempModesIconMap[state.acStatusModel.acMode]!)
state is DeviceControlSuccess && : state is AcModeState
state.code == 'mode' || ? SvgPicture.asset(tempModesIconMap[state.tempModes]!)
state is DeviceControlLoading && : const CircularProgressIndicator(),
state.code == 'mode'
? const CircularProgressIndicator()
: SvgPicture.asset(tempModesIconMap[tempMode]!),
), ),
), ),
), ),

View File

@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.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/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart';
@ -20,7 +22,7 @@ class ACTempWidget extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<ACsBloc, AcsState>(
builder: (context, state) { builder: (context, state) {
return DefaultContainer( return DefaultContainer(
height: 60, height: 60,

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_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_mode_control_unit.dart';
@ -16,7 +18,7 @@ class ACsList extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<ACsBloc, AcsState>(
builder: (context, state) { builder: (context, state) {
return SingleChildScrollView( return SingleChildScrollView(
child: Column( child: Column(
@ -26,9 +28,9 @@ class ACsList extends StatelessWidget {
const SizedBox(height: 10), const SizedBox(height: 10),
const BodySmall(text: "All ACs"), const BodySmall(text: "All ACs"),
const SizedBox(height: 5), const SizedBox(height: 5),
UniversalSwitch( // UniversalSwitch(
category: DevicesCubit.getInstance().chosenCategory!, // category: DevicesCubit.getInstance().chosenCategory!,
), // ),
const SizedBox(height: 10), const SizedBox(height: 10),
const UniversalACTemp(), const UniversalACTemp(),
const SizedBox(height: 10), const SizedBox(height: 10),
@ -38,12 +40,9 @@ class ACsList extends StatelessWidget {
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
itemCount: // itemCount: DevicesCubit.getInstance().chosenCategory!.devices!.length,
DevicesCubit.getInstance().chosenCategory!.devices!.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
DeviceModel ac = DevicesCubit.getInstance() // DeviceModel ac = DevicesCubit.getInstance().chosenCategory!.devices![index];
.chosenCategory!
.devices![index];
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -51,15 +50,13 @@ class ACsList extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
BodySmall( // BodySmall(
text: DevicesCubit.getInstance() // text:
.chosenCategory! // DevicesCubit.getInstance().chosenCategory!.devices![index].name ??
.devices![index] // ""),
.name ??
""),
IconButton( IconButton(
onPressed: () { onPressed: () {
DevicesCubit.getInstance().selectDevice(ac); // DevicesCubit.getInstance().selectDevice(ac);
}, },
icon: const Icon( icon: const Icon(
Icons.arrow_forward_ios, Icons.arrow_forward_ios,
@ -75,17 +72,17 @@ class ACsList extends StatelessWidget {
], ],
), ),
const SizedBox(height: 5), const SizedBox(height: 5),
DevicesDefaultSwitch( // DevicesDefaultSwitch(
model: ac, // model: ac,
), // ),
const SizedBox(height: 10), // const SizedBox(height: 10),
ACTempWidget( // ACTempWidget(
ac, // ac,
), // ),
const SizedBox(height: 10), // const SizedBox(height: 10),
ACModeControlUnit( // ACModeControlUnit(
acDevice: ac, // acDevice: ac,
), // ),
const SizedBox(height: 10), const SizedBox(height: 10),
], ],
); );

View File

@ -1,71 +1,79 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_events.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/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/ac_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_list.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/devices/view/widgets/ACs/category_view_app_bar.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart';
import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/generated/assets.dart';
class ACsView extends StatelessWidget { class ACsView extends StatelessWidget {
const ACsView({super.key}); final DeviceModel? deviceModel;
const ACsView({this.deviceModel, super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocProvider(
builder: (context, state) { create: (context) => ACsBloc(acId: deviceModel?.uuid ?? '')..add(AcsInitial()),
return BlocBuilder<DevicesCubit, DevicesState>( child: BlocBuilder<ACsBloc, AcsState>(
builder: (context, state) { builder: (context, state) {
DeviceModel? selectedAC; // BlocProvider.of<ACsBloc>(context).add(AcsInitial());
if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) { // DeviceModel? selectedAC;
selectedAC = // if (DevicesCubit.getInstance().getSelectedDevice() is DeviceModel) {
DevicesCubit.getInstance().getSelectedDevice() as DeviceModel; // selectedAC = DevicesCubit.getInstance().getSelectedDevice() as DeviceModel;
} // }
return AnnotatedRegion( return AnnotatedRegion(
value: SystemUiOverlayStyle( value: SystemUiOverlayStyle(
statusBarColor: ColorsManager.primaryColor.withOpacity(0.5), statusBarColor: ColorsManager.primaryColor.withOpacity(0.5),
statusBarIconBrightness: Brightness.light, statusBarIconBrightness: Brightness.light,
), ),
child: SafeArea( child: SafeArea(
child: Scaffold( child: Scaffold(
backgroundColor: ColorsManager.backgroundColor, backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
extendBody: true, extendBody: true,
appBar: const CategoryViewAppBar(), appBar: CategoryViewAppBar(
body: Container( title: deviceModel?.name ?? '',
width: MediaQuery.sizeOf(context).width, ),
height: MediaQuery.sizeOf(context).height, body: Container(
decoration: const BoxDecoration( width: MediaQuery.sizeOf(context).width,
image: DecorationImage( height: MediaQuery.sizeOf(context).height,
image: AssetImage( decoration: const BoxDecoration(
Assets.assetsImagesBackground, image: DecorationImage(
), image: AssetImage(
fit: BoxFit.cover, Assets.assetsImagesBackground,
opacity: 0.4,
), ),
fit: BoxFit.cover,
opacity: 0.4,
), ),
child: Padding( ),
padding: EdgeInsets.only( child: Padding(
top: Constants.appBarHeight, padding: EdgeInsets.only(
left: Constants.defaultPadding, top: Constants.appBarHeight,
right: Constants.defaultPadding, left: Constants.defaultPadding,
), right: Constants.defaultPadding,
child: SizedBox.expand(
child: selectedAC != null
? AcInterface(ac: selectedAC)
: const ACsList(),
),
), ),
child: state is AcsLoadingState
? const Center(
child: DefaultContainer(
width: 50, height: 50, child: CircularProgressIndicator()),
)
: SizedBox.expand(
child: deviceModel != null ? AcInterface(ac: deviceModel!) : ACsList(),
),
), ),
), ),
), ),
); ),
}, );
); },
}, ),
); );
} }
} }

View File

@ -5,9 +5,10 @@ import 'package:syncrow_app/utils/context_extension.dart';
import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
import 'package:syncrow_app/utils/resource_manager/constants.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart';
class CategoryViewAppBar extends StatelessWidget class CategoryViewAppBar extends StatelessWidget implements PreferredSizeWidget {
implements PreferredSizeWidget { final String title;
const CategoryViewAppBar({ const CategoryViewAppBar({
required this.title,
super.key, super.key,
}); });
@ -19,11 +20,10 @@ class CategoryViewAppBar extends StatelessWidget
toolbarHeight: Constants.appBarHeight, toolbarHeight: Constants.appBarHeight,
centerTitle: true, centerTitle: true,
title: DisplayMedium( title: DisplayMedium(
text: DevicesCubit.getInstance().chosenCategory!.name!, // text: DevicesCubit.getInstance().chosenCategory!.name!,
style: context.displayMedium.copyWith( text: title,
color: ColorsManager.primaryColor, style: context.displayMedium
fontWeight: FontWeight.bold, .copyWith(color: ColorsManager.primaryColor, fontWeight: FontWeight.bold, fontSize: 14),
),
), ),
leading: IconButton( leading: IconButton(
icon: const Icon( icon: const Icon(
@ -31,7 +31,8 @@ class CategoryViewAppBar extends StatelessWidget
color: ColorsManager.textPrimaryColor, color: ColorsManager.textPrimaryColor,
), ),
onPressed: () { onPressed: () {
DevicesCubit.getInstance().clearCategoriesSelection(context); Navigator.of(context).pop();
// DevicesCubit.getInstance().clearCategoriesSelection(context);
}, },
), ),
); );

View File

@ -1,6 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart';
import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart';
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
@ -15,7 +17,7 @@ class UniversalACTemp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<ACsBloc, AcsState>(
builder: (context, state) { builder: (context, state) {
return DefaultContainer( return DefaultContainer(
height: 60, height: 60,

View File

@ -24,34 +24,34 @@ class CurtainList extends StatelessWidget {
//TODO: move to strings manager //TODO: move to strings manager
const BodySmall(text: "All Curtains"), const BodySmall(text: "All Curtains"),
const SizedBox(height: 5), const SizedBox(height: 5),
UniversalSwitch( // UniversalSwitch(
category: DevicesCubit.get(context).chosenCategory!, // category: DevicesCubit.get(context).chosenCategory!,
), // ),
// other ACs controls // other ACs controls
ListView.builder( ListView.builder(
shrinkWrap: true, shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
itemCount: // itemCount:
DevicesCubit.get(context).chosenCategory!.devices!.length, // DevicesCubit.get(context).chosenCategory!.devices!.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
DeviceModel curtain = // DeviceModel curtain =
DevicesCubit.get(context).chosenCategory!.devices![index]; // DevicesCubit.get(context).chosenCategory!.devices![index];
return Column( return Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const SizedBox(height: 20), const SizedBox(height: 20),
BodySmall( // BodySmall(
text: DevicesCubit.get(context) // text: DevicesCubit.get(context)
.chosenCategory! // .chosenCategory!
.devices![index] // .devices![index]
.name ?? // .name ??
""), // ""),
const SizedBox(height: 5), const SizedBox(height: 5),
DevicesDefaultSwitch( // DevicesDefaultSwitch(
model: curtain, // model: curtain,
), // ),
], ],
); );
}, },

View File

@ -13,7 +13,9 @@ class CurtainListView extends StatelessWidget {
return BlocBuilder<DevicesCubit, DevicesState>( return BlocBuilder<DevicesCubit, DevicesState>(
builder: (context, state) { builder: (context, state) {
return const DefaultScaffold( return const DefaultScaffold(
appBar: CategoryViewAppBar(), appBar: CategoryViewAppBar(
title: '',
),
child: CurtainList(), child: CurtainList(),
); );
}, },

View File

@ -38,7 +38,9 @@ class LightsView extends StatelessWidget {
backgroundColor: ColorsManager.backgroundColor, backgroundColor: ColorsManager.backgroundColor,
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
extendBody: true, extendBody: true,
appBar: const CategoryViewAppBar(), appBar: const CategoryViewAppBar(
title: '',
),
body: Container( body: Container(
width: MediaQuery.sizeOf(context).width, width: MediaQuery.sizeOf(context).width,
height: MediaQuery.sizeOf(context).height, height: MediaQuery.sizeOf(context).height,

View File

@ -2,20 +2,15 @@
/// ///
/// This widget displays the icon and name of the device, along with a switch /// 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. /// to control its state. Tapping on the widget opens the device interface.
library;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart';
import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/wall_sensor_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/wall_sensor_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/ceiling_sensor_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/ceiling_sensor_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.dart';
import 'package:syncrow_app/features/shared_widgets/custom_switch.dart'; import 'package:syncrow_app/features/shared_widgets/custom_switch.dart';
@ -87,14 +82,13 @@ class RoomPageSwitch extends StatelessWidget {
void showDeviceInterface(DeviceModel device, BuildContext context) { void showDeviceInterface(DeviceModel device, BuildContext context) {
switch (device.productType) { switch (device.productType) {
case DeviceType.AC: case DeviceType.AC:
navigateToInterface(AcInterface(ac: device), context); navigateToInterface(ACsView(deviceModel: device), context);
break; break;
case DeviceType.WallSensor: case DeviceType.WallSensor:
navigateToInterface(WallMountedInterface(wallSensor: device), context); navigateToInterface(WallMountedInterface(wallSensor: device), context);
break; break;
case DeviceType.CeilingSensor: case DeviceType.CeilingSensor:
navigateToInterface( navigateToInterface(CeilingSensorInterface(ceilingSensor: device), context);
CeilingSensorInterface(ceilingSensor: device), context);
break; break;
case DeviceType.Curtain: case DeviceType.Curtain:
break; break;

View File

@ -9,8 +9,7 @@ abstract class ApiEndpoints {
static const String deleteUser = '$baseUrl/authentication/user/delete/{id}'; static const String deleteUser = '$baseUrl/authentication/user/delete/{id}';
static const String sendOtp = '$baseUrl/authentication/user/send-otp'; static const String sendOtp = '$baseUrl/authentication/user/send-otp';
static const String verifyOtp = '$baseUrl/authentication/user/verify-otp'; static const String verifyOtp = '$baseUrl/authentication/user/verify-otp';
static const String forgetPassword = static const String forgetPassword = '$baseUrl/authentication/user/forget-password';
'$baseUrl/authentication/user/forget-password';
////////////////////////////////////// Spaces /////////////////////////////////////// ////////////////////////////////////// Spaces ///////////////////////////////////////
@ -20,12 +19,10 @@ abstract class ApiEndpoints {
static const String addCommunityToUser = '$baseUrl/community/user'; static const String addCommunityToUser = '$baseUrl/community/user';
//GET //GET
static const String communityByUuid = '$baseUrl/community/{communityUuid}'; static const String communityByUuid = '$baseUrl/community/{communityUuid}';
static const String communityChild = static const String communityChild = '$baseUrl/community/child/{communityUuid}';
'$baseUrl/community/child/{communityUuid}';
static const String communityUser = '$baseUrl/community/user/{userUuid}'; static const String communityUser = '$baseUrl/community/user/{userUuid}';
//PUT //PUT
static const String renameCommunity = static const String renameCommunity = '$baseUrl/community/rename/{communityUuid}';
'$baseUrl/community/rename/{communityUuid}';
///Building Module ///Building Module
//POST //POST
@ -34,12 +31,10 @@ abstract class ApiEndpoints {
//GET //GET
static const String buildingByUuid = '$baseUrl/building/{buildingUuid}'; static const String buildingByUuid = '$baseUrl/building/{buildingUuid}';
static const String buildingChild = '$baseUrl/building/child/{buildingUuid}'; static const String buildingChild = '$baseUrl/building/child/{buildingUuid}';
static const String buildingParent = static const String buildingParent = '$baseUrl/building/parent/{buildingUuid}';
'$baseUrl/building/parent/{buildingUuid}';
static const String buildingUser = '$baseUrl/building/user/{userUuid}'; static const String buildingUser = '$baseUrl/building/user/{userUuid}';
//PUT //PUT
static const String renameBuilding = static const String renameBuilding = '$baseUrl/building/rename/{buildingUuid}';
'$baseUrl/building/rename/{buildingUuid}';
///Floor Module ///Floor Module
//POST //POST
@ -91,14 +86,12 @@ abstract class ApiEndpoints {
//POST //POST
static const String addDeviceToRoom = '$baseUrl/device/room'; static const String addDeviceToRoom = '$baseUrl/device/room';
static const String addDeviceToGroup = '$baseUrl/device/group'; static const String addDeviceToGroup = '$baseUrl/device/group';
static const String controlDevice = '$baseUrl/device/control'; static const String controlDevice = '$baseUrl/device/{deviceUuid}/control';
//GET //GET
static const String deviceByRoom = '$baseUrl/device/room'; static const String deviceByRoom = '$baseUrl/device/room';
static const String deviceByUuid = '$baseUrl/device/{deviceUuid}'; static const String deviceByUuid = '$baseUrl/device/{deviceUuid}';
static const String deviceFunctions = static const String deviceFunctions = '$baseUrl/device/{deviceUuid}/functions';
'$baseUrl/device/{deviceUuid}/functions'; static const String deviceFunctionsStatus = '$baseUrl/device/{deviceUuid}/functions/status';
static const String deviceFunctionsStatus =
'$baseUrl/device/{deviceUuid}/functions/status';
///Device Permission Module ///Device Permission Module
//POST //POST
@ -106,6 +99,5 @@ abstract class ApiEndpoints {
//GET //GET
static const String devicePermissionList = '$baseUrl/device-permission/list'; static const String devicePermissionList = '$baseUrl/device-permission/list';
//PUT //PUT
static const String editDevicePermission = static const String editDevicePermission = '$baseUrl/device-permission/edit/{userId}';
'$baseUrl/device-permission/edit/{userId}';
} }

View File

@ -10,10 +10,10 @@ class DevicesAPI {
static final HTTPService _httpService = HTTPService(); static final HTTPService _httpService = HTTPService();
static Future<Map<String, dynamic>> controlDevice( static Future<Map<String, dynamic>> controlDevice(
DeviceControlModel controlModel) async { DeviceControlModel controlModel, String deviceId) async {
try { try {
final response = await _httpService.post( final response = await _httpService.post(
path: ApiEndpoints.controlDevice, path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', deviceId),
body: controlModel.toJson(), body: controlModel.toJson(),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
@ -27,26 +27,20 @@ class DevicesAPI {
} }
static Future<List<DevicesCategoryModel>> fetchGroups(String spaceId) async { static Future<List<DevicesCategoryModel>> fetchGroups(String spaceId) async {
Map<String, dynamic> params = { Map<String, dynamic> params = {"homeId": spaceId, "pageSize": 100, "pageNo": 1};
"homeId": spaceId,
"pageSize": 100,
"pageNo": 1
};
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.groupBySpace.replaceAll("{spaceUuid}", spaceId), path: ApiEndpoints.groupBySpace.replaceAll("{spaceUuid}", spaceId),
queryParameters: params, queryParameters: params,
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) => expectedResponseModel: (json) => DevicesCategoryModel.fromJsonList(json['groups']),
DevicesCategoryModel.fromJsonList(json['groups']),
); );
return response; return response;
} }
static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async { static Future<Map<String, dynamic>> getDeviceStatus(String deviceId) async {
final response = await _httpService.get( final response = await _httpService.get(
path: ApiEndpoints.deviceFunctionsStatus path: ApiEndpoints.deviceFunctionsStatus.replaceAll('{deviceUuid}', deviceId),
.replaceAll('{deviceUuid}', deviceId),
showServerMessage: false, showServerMessage: false,
expectedResponseModel: (json) { expectedResponseModel: (json) {
return json; return json;

View File

@ -122,7 +122,7 @@ packages:
source: hosted source: hosted
version: "5.4.1" version: "5.4.1"
equatable: equatable:
dependency: transitive dependency: "direct main"
description: description:
name: equatable name: equatable
sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2

View File

@ -37,6 +37,7 @@ dependencies:
firebase_crashlytics: ^3.4.16 firebase_crashlytics: ^3.4.16
smooth_page_indicator: ^1.1.0 smooth_page_indicator: ^1.1.0
html: ^0.15.4 html: ^0.15.4
equatable: ^2.0.5
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: