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