From 9897c19dad0bb193d2d11f7d68c589b1fe3e8a34 Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 10 Feb 2025 10:26:02 +0300 Subject: [PATCH 1/9] fixes bugs and add project id staging --- .../devices/bloc/acs_bloc/acs_bloc.dart | 40 ++++++++++--------- lib/features/devices/bloc/devices_cubit.dart | 13 ++---- .../widgets/ACs/ac_interface_controls.dart | 1 + .../view/widgets/ACs/ac_timer_page.dart | 34 ++++++++-------- .../devices/view/widgets/ACs/acs_view.dart | 4 -- .../ceiling_sensor_interface.dart | 6 +-- .../ceiling_sensor/max_distance_control.dart | 15 +++---- .../view/widgets/devices_view_body.dart | 11 +---- lib/services/api/devices_api.dart | 13 +----- lib/services/api/home_creation_api.dart | 2 +- lib/services/api/home_management_api.dart | 5 ++- lib/services/api/scene_api.dart | 2 +- lib/services/api/spaces_api.dart | 4 +- lib/utils/constants/temp_const.dart | 3 +- 14 files changed, 67 insertions(+), 86 deletions(-) diff --git a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart index b0b43af..95de36f 100644 --- a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart +++ b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart @@ -136,7 +136,6 @@ class ACsBloc extends Bloc { ac.acSwitch = acSwitchValue; } } - _setAllAcsTempsAndSwitches(); _emitAcsStatus(emit); @@ -458,24 +457,27 @@ class ACsBloc extends Bloc { } void _getCounterValue(GetCounterEvent event, Emitter emit) async { - try { - emit(AcsLoadingState()); - var response = await DevicesAPI.getDeviceStatus(acId); - List statusModelList = []; - for (var status in response['status']) { - statusModelList.add(StatusModel.fromJson(status)); - } - deviceStatus = - AcStatusModel.fromJson(response['productUuid'], statusModelList); - - if (event.deviceCode == 'countdown_time') { - deviceStatus.countdown1 > 0 - ? _onStartTimer(deviceStatus.countdown1) - : emit(UpdateTimerState(seconds: deviceStatus.countdown1)); - } - } catch (e) { - emit(AcsFailedState(errorMessage: e.toString())); - return; + emit(AcsLoadingState()); + var response = await DevicesAPI.getDeviceStatus(acId); + List statusModelList = []; + for (var status in response['status']) { + statusModelList.add(StatusModel.fromJson(status)); + } + deviceStatus = + AcStatusModel.fromJson(response['productUuid'], statusModelList); + deviceStatus.countdown1; + var duration; + if (deviceStatus.countdown1 == 5) { + duration = const Duration(minutes: 30); + var countNum = duration.inSeconds; + _onStartTimer(countNum); + } else if (deviceStatus.countdown1 > 5) { + duration = Duration(minutes: deviceStatus.countdown1 * 6); + var countNum = duration.inSeconds; + _onStartTimer(countNum); + } else { + _timer?.cancel(); + emit(TimerRunComplete()); } } diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 6006e1a..2949072 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -48,7 +48,6 @@ class DevicesCubit extends Cubit { return _instance ??= DevicesCubit._(); } - @override Future close() { _instance = null; @@ -478,8 +477,7 @@ class DevicesCubit extends Cubit { final statusIndex = device.status.indexWhere((s) => s.code == switchCode); if (statusIndex != -1) { - final currentValue = device.status[statusIndex].value ?? false; - final toggledValue = !currentValue; + final toggledValue = control.value; final controlRequest = DeviceControlModel( code: switchCode, value: toggledValue, deviceId: deviceUuid); final response = @@ -518,8 +516,7 @@ class DevicesCubit extends Cubit { final statusIndex = device.status.indexWhere((s) => s.code == switchCode); if (statusIndex != -1) { - final currentValue = device.status[statusIndex].value ?? false; - final toggledValue = !currentValue; + final toggledValue = control.value; final controlRequest = DeviceControlModel( code: switchCode, value: toggledValue, deviceId: deviceUuid); final response = @@ -556,8 +553,7 @@ class DevicesCubit extends Cubit { final statusIndex = device.status.indexWhere((s) => s.code == switchCode); if (statusIndex != -1) { - final currentValue = device.status[statusIndex].value ?? false; - final toggledValue = !currentValue; + final toggledValue = control.value; final controlRequest = DeviceControlModel( code: switchCode, value: toggledValue, deviceId: deviceUuid); final response = @@ -589,8 +585,7 @@ class DevicesCubit extends Cubit { final statusIndex = device.status.indexWhere((s) => s.code == 'switch_1'); if (statusIndex != -1) { - final currentValue = device.status[statusIndex].value ?? false; - final toggledValue = !currentValue; + final toggledValue = control.value; final controlRequest = DeviceControlModel( code: 'switch_1', value: toggledValue, deviceId: deviceUuid); final response = 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 c02bf6c..97af020 100644 --- a/lib/features/devices/view/widgets/ACs/ac_interface_controls.dart +++ b/lib/features/devices/view/widgets/ACs/ac_interface_controls.dart @@ -43,6 +43,7 @@ class AcInterfaceControls extends StatelessWidget { PageRouteBuilder( pageBuilder: (context, animation1, animation2) => AcTimerPage( + deviceStatus: deviceStatus, device: deviceModel, deviceCode: deviceModel.type!, switchCode: '', diff --git a/lib/features/devices/view/widgets/ACs/ac_timer_page.dart b/lib/features/devices/view/widgets/ACs/ac_timer_page.dart index 460a1ec..4a61d98 100644 --- a/lib/features/devices/view/widgets/ACs/ac_timer_page.dart +++ b/lib/features/devices/view/widgets/ACs/ac_timer_page.dart @@ -7,7 +7,7 @@ import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_st import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; - +import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/custom_halfhour_timer_picker.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; @@ -20,10 +20,13 @@ class AcTimerPage extends StatelessWidget { final DeviceModel device; final String deviceCode; final String switchCode; + final AcStatusModel deviceStatus; + const AcTimerPage( {required this.device, required this.deviceCode, required this.switchCode, + required this.deviceStatus, super.key}); @override @@ -37,27 +40,24 @@ class AcTimerPage extends StatelessWidget { create: (context) => ACsBloc(acId: device.uuid ?? ''), child: BlocBuilder( builder: (context, state) { - final oneGangBloc = BlocProvider.of(context); + final acBloc = BlocProvider.of(context); Duration duration = Duration.zero; int selectedValue = 0; - int countNum = 0; - if (state is UpdateTimerState) { + if (state is AcsInitialState) { + acBloc.add(GetCounterEvent(deviceCode: deviceCode)); + } else if (state is UpdateTimerState) { countNum = state.seconds; } else if (state is TimerRunInProgress) { countNum = state.remainingTime; } else if (state is TimerRunComplete) { countNum = 0; } - // else if (state is LoadingNewSate) { - // countNum = 0; - // } - return PopScope( canPop: false, onPopInvoked: (didPop) { if (!didPop) { - oneGangBloc.add(OnClose()); + acBloc.add(OnClose()); Navigator.pop(context); } }, @@ -90,7 +90,7 @@ class AcTimerPage extends StatelessWidget { ), ), Center( - child: Container( + child: SizedBox( child: Column( mainAxisAlignment: MainAxisAlignment.center, @@ -102,7 +102,7 @@ class AcTimerPage extends StatelessWidget { .slidingBlueColor, fontSize: 40, ) - : Container( + : SizedBox( child: CustomHalfHourPicker( onValueChanged: (value) { selectedValue = @@ -120,8 +120,6 @@ class AcTimerPage extends StatelessWidget { countNum = duration.inSeconds; } - print( - "Selected Value: $selectedValue, Duration: $duration"); }, ), ), @@ -131,12 +129,14 @@ class AcTimerPage extends StatelessWidget { return; } if (countNum > 0) { - oneGangBloc.add(SetCounterValue( + acBloc.add(SetCounterValue( seconds: countNum, - deviceCode:'countdown_time', + deviceCode: + 'countdown_time', duration: selectedValue)); - } else if (duration != Duration.zero) { - oneGangBloc.add(SetCounterValue( + } else if (duration != + Duration.zero) { + acBloc.add(SetCounterValue( seconds: 0, deviceCode: 'countdown_time', diff --git a/lib/features/devices/view/widgets/ACs/acs_view.dart b/lib/features/devices/view/widgets/ACs/acs_view.dart index 5bde723..7ced282 100644 --- a/lib/features/devices/view/widgets/ACs/acs_view.dart +++ b/lib/features/devices/view/widgets/ACs/acs_view.dart @@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; -import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/ac_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_list.dart'; @@ -23,8 +22,6 @@ class ACsView extends StatelessWidget { @override Widget build(BuildContext context) { - print("ACsView deviceModel UUID: ${deviceModel?.uuid}"); - return BlocProvider( create: (context) => ACsBloc(acId: deviceModel?.uuid ?? '') ..add(AcsInitial(allAcs: deviceModel != null ? false : true)), @@ -41,7 +38,6 @@ class ACsView extends StatelessWidget { extendBody: true, appBar: deviceModel != null ? DeviceAppbar( - //BlocProvider.of(context).deviceStatus.acSwitch.toString() value: true, deviceName: deviceModel!.name!, deviceUuid: deviceModel!.uuid!, diff --git a/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart b/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart index 77101a7..ce3ee94 100644 --- a/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart +++ b/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart @@ -306,7 +306,7 @@ class CeilingSensorInterface extends StatelessWidget { .toString() .toLowerCase() .replaceAll('sec', 's') - .replaceAll('1hr', '1hour'), // Replacing "sec" with "s" + .replaceAll('1hr', '1hour'), code: 'nobody_time')); } } else if (title == 'Maximum Distance') { @@ -344,7 +344,7 @@ class CeilingSensorInterface extends StatelessWidget { context, MaterialPageRoute(builder: (context) => const CeilingHelpDescription()), ); - } else if (title == 'Induction History') { + } else if (title == 'Presence Record') { Navigator.push( context, MaterialPageRoute( @@ -393,7 +393,7 @@ class CeilingSensorInterface extends StatelessWidget { 'val': nobodyTimeVal, }, { - 'title': 'Induction History', + 'title': 'Presence Record', 'icon': Assets.assetsIconsPresenceSensorAssetsInductionRecording, 'page': null, 'withArrow': false, diff --git a/lib/features/devices/view/widgets/ceiling_sensor/max_distance_control.dart b/lib/features/devices/view/widgets/ceiling_sensor/max_distance_control.dart index c0ffd1d..575f6cd 100644 --- a/lib/features/devices/view/widgets/ceiling_sensor/max_distance_control.dart +++ b/lib/features/devices/view/widgets/ceiling_sensor/max_distance_control.dart @@ -31,12 +31,12 @@ class MaxDistanceControl extends StatefulWidget { } int _parseValue(String value) { - if (value.endsWith('sec')) { - return int.parse(value.replaceAll('sec', '').trim()); + if (value.endsWith('s')) { + return int.parse(value.replaceAll('s', '').trim()); } else if (value.endsWith('min')) { return int.parse(value.replaceAll('min', '').trim()) * 60; - } else if (value.endsWith('hr')) { - return int.parse(value.replaceAll('hr', '').trim()) * 3600; + } else if (value.endsWith('hour')) { + return int.parse(value.replaceAll('hour', '').trim()) * 3600; } return 0; // Default to 0 if the format is unrecognized } @@ -58,7 +58,7 @@ class MaxDistanceControlState extends State { String _formatLabel(double seconds) { if (seconds == 0) return 'None'; - if (seconds < 60) return '${seconds.toInt()}sec'; + if (seconds < 60) return '${seconds.toInt()}s'; if (seconds < 3600) { final minutes = (seconds / 60).round(); return '${minutes}min'; @@ -90,7 +90,6 @@ class MaxDistanceControlState extends State { @override Widget build(BuildContext context) { final double currentSeconds = _stepValues[_currentIndex]; - return Dialog( child: Container( decoration: BoxDecoration( @@ -128,7 +127,9 @@ class MaxDistanceControlState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ TitleMedium( - text: _formatLabel(currentSeconds), + text: _formatLabel(currentSeconds) + .replaceAll('1hr', '1hour') + .replaceAllMapped(RegExp(r's$'), (match) => 'sec'), style: context.titleMedium.copyWith( color: Colors.black, fontWeight: FontsManager.bold, diff --git a/lib/features/devices/view/widgets/devices_view_body.dart b/lib/features/devices/view/widgets/devices_view_body.dart index bca3173..1777318 100644 --- a/lib/features/devices/view/widgets/devices_view_body.dart +++ b/lib/features/devices/view/widgets/devices_view_body.dart @@ -21,32 +21,28 @@ class DevicesViewBody extends StatelessWidget { return BlocBuilder( builder: (context, homeState) { final homeCubit = HomeCubit.getInstance(); - // Handle state priority: Errors first if (homeState is ActivationError) { return const CreateUnitWidget(); } - // Handle loading states if (homeState is GetSpacesLoading || homeState is HomeLoading) { return const Center(child: CircularProgressIndicator()); } - // Handle error states if (homeState is GetSpacesError) { return const CreateUnitWidget(); } - // Handle success states if (homeState is GetSpacesSuccess || homeState is RoomUnSelected || homeState is RoomSelected || - homeState is NavChangePage) { + homeState is NavChangePage || + homeState is GetSpaceRoomsSuccess) { // Show empty state if no spaces if (homeCubit.spaces.isEmpty) { return const CreateUnitWidget(); } - return BlocBuilder( builder: (context, devicesState) { // Devices loading states @@ -55,7 +51,6 @@ class DevicesViewBody extends StatelessWidget { devicesState is GetDevicesLoading) { return const Center(child: CircularProgressIndicator()); } - // Devices error state if (devicesState is GetDevicesError) { return Center(child: BodyLarge(text: devicesState.errorMsg)); @@ -65,7 +60,6 @@ class DevicesViewBody extends StatelessWidget { }, ); } - // Fallback for unknown states return const Center(child: BodyLarge(text: '')); }, @@ -74,7 +68,6 @@ class DevicesViewBody extends StatelessWidget { Widget _buildMainContent(BuildContext context, HomeCubit homeCubit) { final devicesCubit = context.read(); - return Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, diff --git a/lib/services/api/devices_api.dart b/lib/services/api/devices_api.dart index a6ff88b..b9b27b5 100644 --- a/lib/services/api/devices_api.dart +++ b/lib/services/api/devices_api.dart @@ -51,14 +51,11 @@ class DevicesAPI { static Future> controlDevice( DeviceControlModel controlModel, String deviceId) async { try { - print('object-*/-*/-*/${controlModel.toJson()}'); final response = await _httpService.post( path: ApiEndpoints.controlDevice.replaceAll('{deviceUuid}', deviceId), body: controlModel.toJson(), showServerMessage: true, expectedResponseModel: (json) { - print('object-*/-*/-*/${json}'); - return json; }, ); @@ -191,7 +188,6 @@ class DevicesAPI { path: ApiEndpoints.deviceByUuid.replaceAll('{deviceUuid}', deviceId), showServerMessage: false, expectedResponseModel: (json) { - print('object-*-*-*${json}'); return json; }); return response; @@ -229,7 +225,7 @@ class DevicesAPI { .replaceAll('{communityUuid}', communityUuid) .replaceAll('{spaceUuid}', spaceUuid) .replaceAll('{subSpaceUuid}', roomId) - .replaceAll('{projectUuid}', TempConst.projectId); + .replaceAll('{projectUuid}', TempConst.projectIdDev); final response = await _httpService.get( path: path, @@ -569,21 +565,16 @@ class DevicesAPI { required String communityUuid, required String spaceUuid, }) async { - print('communityUuid=$communityUuid'); - print('spaceUuid=$spaceUuid'); - print('projectUuid=${TempConst.projectId}'); - try { final String path = ApiEndpoints.getAllDevices .replaceAll('{communityUuid}', communityUuid) .replaceAll('{spaceUuid}', spaceUuid) - .replaceAll('{projectUuid}', TempConst.projectId); + .replaceAll('{projectUuid}', TempConst.projectIdDev); final response = await _httpService.get( path: path, showServerMessage: false, expectedResponseModel: (json) { - print('response-*/-*/$json'); final data = json['data']; if (data == null || data.isEmpty) { diff --git a/lib/services/api/home_creation_api.dart b/lib/services/api/home_creation_api.dart index 351701d..9d3fd13 100644 --- a/lib/services/api/home_creation_api.dart +++ b/lib/services/api/home_creation_api.dart @@ -150,7 +150,7 @@ class HomeCreation { final fullPath = ApiEndpoints.addSubSpace .replaceAll('{communityUuid}', communityId) .replaceAll('{spaceUuid}', spaceId) - .replaceAll('{projectUuid}', TempConst.projectId); + .replaceAll('{projectUuid}', TempConst.projectIdDev); final response = await _httpService.post( path: fullPath, body: body, diff --git a/lib/services/api/home_management_api.dart b/lib/services/api/home_management_api.dart index cd4f2c0..abeff8e 100644 --- a/lib/services/api/home_management_api.dart +++ b/lib/services/api/home_management_api.dart @@ -40,7 +40,7 @@ class HomeManagementAPI { final path = ApiEndpoints.spaceDevices .replaceAll('{communityUuid}', communityUuid) .replaceAll('{spaceUuid}', spaceUuid) - .replaceAll('{projectUuid}', TempConst.projectId); + .replaceAll('{projectUuid}', TempConst.projectIdDev); await _httpService.get( path: path, @@ -67,6 +67,7 @@ class HomeManagementAPI { try { final response = await _httpService.post( path: ApiEndpoints.assignDeviceToRoom + .replaceAll('{projectUuid}', TempConst.projectIdDev) .replaceAll('{communityUuid}', communityId) .replaceAll('{spaceUuid}', spaceId) .replaceAll('{subSpaceUuid}', subSpaceId) @@ -90,7 +91,7 @@ class HomeManagementAPI { .replaceAll('{spaceUuid}', spaceId) .replaceAll('{subSpaceUuid}', subSpaceId) .replaceAll('{deviceUuid}', deviceId) - .replaceAll('{projectUuid}', TempConst.projectId), + .replaceAll('{projectUuid}', TempConst.projectIdDev), expectedResponseModel: (json) { return json; }, diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index 3eb723f..0281417 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -57,7 +57,7 @@ class SceneApi { path: ApiEndpoints.getUnitScenes .replaceAll('{spaceUuid}', unitId) .replaceAll('{communityUuid}', communityId) - .replaceAll('{projectUuid}', TempConst.projectId), + .replaceAll('{projectUuid}', TempConst.projectIdDev), queryParameters: {'showInHomePage': showInDevice}, showServerMessage: false, expectedResponseModel: (json) { diff --git a/lib/services/api/spaces_api.dart b/lib/services/api/spaces_api.dart index fbe066a..3864f60 100644 --- a/lib/services/api/spaces_api.dart +++ b/lib/services/api/spaces_api.dart @@ -38,7 +38,7 @@ class SpacesAPI { final path = ApiEndpoints.listSubspace .replaceFirst('{communityUuid}', communityId) .replaceFirst('{spaceUuid}', spaceId) - .replaceAll('{projectUuid}', TempConst.projectId); + .replaceAll('{projectUuid}', TempConst.projectIdDev); final response = await _httpService.get( path: path, @@ -71,7 +71,7 @@ class SpacesAPI { path: ApiEndpoints.invitationCode .replaceAll('{unitUuid}', unitId) .replaceAll('{communityUuid}', communityId) - .replaceAll('{projectUuid}', TempConst.projectId), + .replaceAll('{projectUuid}', TempConst.projectIdDev), showServerMessage: false, expectedResponseModel: (json) { if (json != null && json['data'] != null) { diff --git a/lib/utils/constants/temp_const.dart b/lib/utils/constants/temp_const.dart index e5847b9..237fc22 100644 --- a/lib/utils/constants/temp_const.dart +++ b/lib/utils/constants/temp_const.dart @@ -1,3 +1,4 @@ class TempConst { - static const projectId = '0e62577c-06fa-41b9-8a92-99a21fbaf51c'; + static const projectIdDev = '0e62577c-06fa-41b9-8a92-99a21fbaf51c'; + static const projectIdStag = 'bcda711e-9fc2-4168-a05e-171b4026d1ff'; } From efed5f55a710a6f8e0a1d6148b2bfe8876b7cc73 Mon Sep 17 00:00:00 2001 From: mohammad Date: Tue, 11 Feb 2025 11:05:13 +0300 Subject: [PATCH 2/9] add project id to env file and hide about --- .env.dev | 3 ++- .env.prod | 3 ++- .env.staging | 3 ++- lib/features/menu/bloc/menu_cubit.dart | 12 ++++++------ lib/utils/constants/temp_const.dart | 5 +++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.env.dev b/.env.dev index e77609d..406ddc2 100644 --- a/.env.dev +++ b/.env.dev @@ -1,2 +1,3 @@ ENV_NAME=development -BASE_URL=https://syncrow-dev.azurewebsites.net \ No newline at end of file +BASE_URL=https://syncrow-dev.azurewebsites.net +projectId=0e62577c-06fa-41b9-8a92-99a21fbaf51c diff --git a/.env.prod b/.env.prod index 4e9dcb8..3b0ae1f 100644 --- a/.env.prod +++ b/.env.prod @@ -1,2 +1,3 @@ ENV_NAME=production -BASE_URL=https://syncrow-staging.azurewebsites.net \ No newline at end of file +BASE_URL=https://syncrow-staging.azurewebsites.net +projectId=bcda711e-9fc2-4168-a05e-171b4026d1ff diff --git a/.env.staging b/.env.staging index 9565b42..db01ceb 100644 --- a/.env.staging +++ b/.env.staging @@ -1,2 +1,3 @@ ENV_NAME=staging -BASE_URL=https://syncrow-staging.azurewebsites.net \ No newline at end of file +BASE_URL=https://syncrow-staging.azurewebsites.net +projectId=bcda711e-9fc2-4168-a05e-171b4026d1ff diff --git a/lib/features/menu/bloc/menu_cubit.dart b/lib/features/menu/bloc/menu_cubit.dart index b868624..624112f 100644 --- a/lib/features/menu/bloc/menu_cubit.dart +++ b/lib/features/menu/bloc/menu_cubit.dart @@ -154,11 +154,11 @@ class MenuCubit extends Cubit { 'title': 'Legal Information', 'color': const Color(0xFF001B72), 'buttons': [ - { - 'title': 'About', - 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsAbout, - 'page': null - }, + // { + // 'title': 'About', + // 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsAbout, + // 'page': null + // }, { 'title': 'Privacy Policy', 'Icon': Assets.assetsIconsMenuIconsLeagalInfoIconsPrivacyPolicy, @@ -176,7 +176,7 @@ class MenuCubit extends Cubit { Future fetchMenuSections() async { emit(MenuLoading()); try { - emit(MenuItemsLoaded(menuSections)); + emit(MenuItemsLoaded(menuSections)); } catch (e) { emit(MenuError(e.toString())); } diff --git a/lib/utils/constants/temp_const.dart b/lib/utils/constants/temp_const.dart index 237fc22..9ed0b6c 100644 --- a/lib/utils/constants/temp_const.dart +++ b/lib/utils/constants/temp_const.dart @@ -1,4 +1,5 @@ +import 'package:flutter_dotenv/flutter_dotenv.dart'; + class TempConst { - static const projectIdDev = '0e62577c-06fa-41b9-8a92-99a21fbaf51c'; - static const projectIdStag = 'bcda711e-9fc2-4168-a05e-171b4026d1ff'; + static String projectIdDev = dotenv.env['projectId'] ?? ''; } From 36dfe2c85ec80137b3a70c0e2c1366d629d35869 Mon Sep 17 00:00:00 2001 From: mohammad Date: Wed, 12 Feb 2025 12:06:00 +0300 Subject: [PATCH 3/9] change the key --- .env.dev | 2 +- .env.prod | 2 +- .env.staging | 2 +- lib/utils/constants/temp_const.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env.dev b/.env.dev index 406ddc2..4d4dde7 100644 --- a/.env.dev +++ b/.env.dev @@ -1,3 +1,3 @@ ENV_NAME=development BASE_URL=https://syncrow-dev.azurewebsites.net -projectId=0e62577c-06fa-41b9-8a92-99a21fbaf51c +PROJECT_ID=0e62577c-06fa-41b9-8a92-99a21fbaf51c diff --git a/.env.prod b/.env.prod index 3b0ae1f..9766abc 100644 --- a/.env.prod +++ b/.env.prod @@ -1,3 +1,3 @@ ENV_NAME=production BASE_URL=https://syncrow-staging.azurewebsites.net -projectId=bcda711e-9fc2-4168-a05e-171b4026d1ff +PROJECT_ID=bcda711e-9fc2-4168-a05e-171b4026d1ff diff --git a/.env.staging b/.env.staging index db01ceb..78da428 100644 --- a/.env.staging +++ b/.env.staging @@ -1,3 +1,3 @@ ENV_NAME=staging BASE_URL=https://syncrow-staging.azurewebsites.net -projectId=bcda711e-9fc2-4168-a05e-171b4026d1ff +PROJECT_ID=bcda711e-9fc2-4168-a05e-171b4026d1ff diff --git a/lib/utils/constants/temp_const.dart b/lib/utils/constants/temp_const.dart index 9ed0b6c..ab9bd72 100644 --- a/lib/utils/constants/temp_const.dart +++ b/lib/utils/constants/temp_const.dart @@ -1,5 +1,5 @@ import 'package:flutter_dotenv/flutter_dotenv.dart'; class TempConst { - static String projectIdDev = dotenv.env['projectId'] ?? ''; + static String projectIdDev = dotenv.env['PROJECT_ID'] ?? ''; } From 67209961b426bdded6fc05e4429e28b12a742e04 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Sat, 15 Feb 2025 11:54:02 +0400 Subject: [PATCH 4/9] added project model --- lib/features/auth/model/project_model.dart | 27 +++++++++++ lib/features/auth/model/user_model.dart | 53 ++++++++++++--------- lib/features/common/bloc/project_cubit.dart | 19 ++++++++ 3 files changed, 76 insertions(+), 23 deletions(-) create mode 100644 lib/features/auth/model/project_model.dart create mode 100644 lib/features/common/bloc/project_cubit.dart diff --git a/lib/features/auth/model/project_model.dart b/lib/features/auth/model/project_model.dart new file mode 100644 index 0000000..4f2f424 --- /dev/null +++ b/lib/features/auth/model/project_model.dart @@ -0,0 +1,27 @@ +class Project { + final String uuid; + final String name; + final String description; + + const Project({ + required this.uuid, + required this.name, + required this.description, + }); + + factory Project.fromJson(Map json) { + return Project( + uuid: json['uuid'] as String, + name: json['name'] as String, + description: json['description'] as String, + ); + } + + Map toJson() { + return { + 'uuid': uuid, + 'name': name, + 'description': description, + }; + } +} diff --git a/lib/features/auth/model/user_model.dart b/lib/features/auth/model/user_model.dart index 143b114..0f50a8b 100644 --- a/lib/features/auth/model/user_model.dart +++ b/lib/features/auth/model/user_model.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:flutter/foundation.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/auth/model/token.dart'; class UserModel { @@ -20,6 +21,7 @@ class UserModel { final bool? hasAcceptedAppAgreement; final DateTime? appAgreementAcceptedAt; final Role? role; + final Project? project; UserModel({ required this.uuid, @@ -38,6 +40,7 @@ class UserModel { required this.hasAcceptedAppAgreement, required this.appAgreementAcceptedAt, required this.role, + required this.project, }); factory UserModel.fromJson(Map json) { @@ -62,33 +65,35 @@ class UserModel { ? DateTime.parse(json['appAgreementAcceptedAt']) : null, role: json['role'] != null ? Role.fromJson(json['role']) : null, + project: + json['project'] != null ? Project.fromJson(json['project']) : null, ); } factory UserModel.fromToken(Token token) { Map tempJson = Token.decodeToken(token.accessToken); return UserModel( - uuid: tempJson['uuid'].toString(), - email: tempJson['email'], - lastName: tempJson['lastName'], - firstName: tempJson['firstName'], - profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']), - phoneNumber: null, - isEmailVerified: null, - isAgreementAccepted: null, - regionUuid: null, - regionName: tempJson['region']?['regionName'], - timeZone: tempJson['timezone']?['timeZoneOffset'], - hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'], - webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null - ? DateTime.parse(tempJson['webAgreementAcceptedAt']) - : null, - hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'], - appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null - ? DateTime.parse(tempJson['appAgreementAcceptedAt']) - : null, - role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null, - ); + uuid: tempJson['uuid'].toString(), + email: tempJson['email'], + lastName: tempJson['lastName'], + firstName: tempJson['firstName'], + profilePicture: UserModel.decodeBase64Image(tempJson['profilePicture']), + phoneNumber: null, + isEmailVerified: null, + isAgreementAccepted: null, + regionUuid: null, + regionName: tempJson['region']?['regionName'], + timeZone: tempJson['timezone']?['timeZoneOffset'], + hasAcceptedWebAgreement: tempJson['hasAcceptedWebAgreement'], + webAgreementAcceptedAt: tempJson['webAgreementAcceptedAt'] != null + ? DateTime.parse(tempJson['webAgreementAcceptedAt']) + : null, + hasAcceptedAppAgreement: tempJson['hasAcceptedAppAgreement'], + appAgreementAcceptedAt: tempJson['appAgreementAcceptedAt'] != null + ? DateTime.parse(tempJson['appAgreementAcceptedAt']) + : null, + role: tempJson['role'] != null ? Role.fromJson(tempJson['role']) : null, + project: null); } static Uint8List? decodeBase64Image(String? base64String) { @@ -137,8 +142,10 @@ class Role { factory Role.fromJson(Map json) { return Role( uuid: json['uuid'], - createdAt: json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null, - updatedAt: json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null, + createdAt: + json['createdAt'] != null ? DateTime.parse(json['createdAt']) : null, + updatedAt: + json['updatedAt'] != null ? DateTime.parse(json['updatedAt']) : null, type: json['type'], ); } diff --git a/lib/features/common/bloc/project_cubit.dart b/lib/features/common/bloc/project_cubit.dart new file mode 100644 index 0000000..ab0c891 --- /dev/null +++ b/lib/features/common/bloc/project_cubit.dart @@ -0,0 +1,19 @@ +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_secure_storage/flutter_secure_storage.dart'; + +class ProjectCubit extends Cubit { + final FlutterSecureStorage storage; + static const String projectKey = "selected_project_uuid"; + + ProjectCubit(this.storage) : super(null); + + Future setProjectUUID(String newUUID) async { + await storage.write(key: projectKey, value: newUUID); + emit(newUUID); + } + + Future clearProjectUUID() async { + await storage.delete(key: projectKey); + emit(null); + } +} From 3f7f7ce49f82ed55337ca926d45b9559ff06a5f4 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Sun, 16 Feb 2025 20:55:13 +0400 Subject: [PATCH 5/9] updated project hardcoded values --- lib/features/app_layout/bloc/home_cubit.dart | 17 +++++-- .../6_scene_switch_bloc/6_scene_bloc.dart | 15 ++++-- .../device_manager_bloc.dart | 44 ++++++++++------ .../device_scene_bloc.dart | 19 +++++-- lib/features/devices/bloc/devices_cubit.dart | 15 ++++-- .../bloc/four_scene_bloc/four_scene_bloc.dart | 7 ++- .../devices/bloc/sos_bloc/sos_bloc.dart | 25 ++++++++-- .../create_unit_bloc/create_unit_bloc.dart | 9 +++- .../manage_unit_bloc/manage_unit_bloc.dart | 50 ++++++++++++++----- .../menu/bloc/profile_bloc/profile_bloc.dart | 33 ++++++++---- .../scene/bloc/scene_bloc/scene_bloc.dart | 9 +++- lib/services/api/devices_api.dart | 6 ++- lib/services/api/home_creation_api.dart | 3 +- lib/services/api/home_management_api.dart | 12 ++--- lib/services/api/scene_api.dart | 4 +- lib/services/api/spaces_api.dart | 8 +-- 16 files changed, 199 insertions(+), 77 deletions(-) diff --git a/lib/features/app_layout/bloc/home_cubit.dart b/lib/features/app_layout/bloc/home_cubit.dart index adad8c4..f4ed015 100644 --- a/lib/features/app_layout/bloc/home_cubit.dart +++ b/lib/features/app_layout/bloc/home_cubit.dart @@ -10,6 +10,7 @@ import 'package:share_plus/share_plus.dart'; import 'package:syncrow_app/features/app_layout/model/permission_model.dart'; import 'package:syncrow_app/features/app_layout/model/space_model.dart'; import 'package:syncrow_app/features/app_layout/view/widgets/app_bar_home_dropdown.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/auth/model/user_model.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/subspace_model.dart'; @@ -28,6 +29,7 @@ import 'package:syncrow_app/navigation/routing_constants.dart'; import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/profile_api.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; part 'home_state.dart'; @@ -67,6 +69,8 @@ class HomeCubit extends Cubit { var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey); user = await ProfileApi().fetchUserInfo(uuid); + project = user?.project; + emit(HomeUserInfoLoaded(user!)); } catch (e) { return; @@ -175,6 +179,8 @@ class HomeCubit extends Cubit { SubSpaceModel? selectedRoom; + Project? project; + PageController devicesPageController = PageController(); PageController roomsPageController = PageController(); @@ -324,8 +330,8 @@ class HomeCubit extends Cubit { //////////////////////////////////////// API //////////////////////////////////////// generateInvitation(SpaceModel unit) async { try { - final invitationCode = - await SpacesAPI.generateInvitationCode(unit.id, unit.community.uuid); + final invitationCode = await SpacesAPI.generateInvitationCode(unit.id, + unit.community.uuid, project?.uuid ?? TempConst.projectIdDev); if (invitationCode.isNotEmpty) { Share.share('The invitation code is $invitationCode'); CustomSnackBar.displaySnackBar( @@ -380,8 +386,10 @@ class HomeCubit extends Cubit { fetchRoomsByUnitId(SpaceModel space) async { emitSafe(GetSpaceRoomsLoading()); try { - space.subspaces = - await SpacesAPI.getSubSpaceBySpaceId(space.community.uuid, space.id); + space.subspaces = await SpacesAPI.getSubSpaceBySpaceId( + space.community.uuid, + space.id, + project?.uuid ?? TempConst.projectIdDev); } catch (failure) { emitSafe(GetSpaceRoomsError(failure.toString())); return; @@ -414,7 +422,6 @@ class HomeCubit extends Cubit { emitSafe(ActivationError(errMessage: errorMsg)); return false; } - } /////////////////////////////////////// Nav /////////////////////////////////////// diff --git a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart index 48fe85f..c77b11b 100644 --- a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart +++ b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart'; import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; @@ -16,6 +17,7 @@ import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/home_management_api.dart'; import 'package:syncrow_app/services/api/scene_api.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; class SixSceneBloc extends Bloc { @@ -112,8 +114,9 @@ class SixSceneBloc extends Bloc { FetchRoomsEvent event, Emitter emit) async { try { emit(SixSceneLoadingState()); + Project? project = HomeCubit.getInstance().project; roomsList = await SpacesAPI.getSubSpaceBySpaceId( - event.unit.community.uuid, event.unit.id); + event.unit.community.uuid, event.unit.id, project?.uuid ?? TempConst.projectIdDev); emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList)); } catch (e) { emit(SixSceneFailedState(errorMessage: e.toString())); @@ -125,12 +128,14 @@ class SixSceneBloc extends Bloc { try { emit(SixSceneLoadingState()); if (_hasSelectionChanged) { + Project? project = HomeCubit.getInstance().project; await HomeManagementAPI.assignDeviceToRoom( - event.unit.community.uuid, event.unit.id, event.roomId, sixSceneId); + event.unit.community.uuid, event.unit.id, event.roomId, sixSceneId, project?.uuid ?? TempConst.projectIdDev); final devicesList = await DevicesAPI.getDevicesByRoomId( communityUuid: event.unit.community.uuid, spaceUuid: event.unit.id, - roomId: event.roomId); + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); List allDevicesIds = []; allDevices.forEach((element) { allDevicesIds.add(element.uuid!); @@ -341,8 +346,10 @@ class SixSceneBloc extends Bloc { emit(SixSceneLoadingState()); try { + Project? project = HomeCubit.getInstance().project; + allScenes = await SceneApi.getScenesByUnitId( - event.unitId, event.unit.community.uuid, + event.unitId, event.unit.community.uuid, project?.uuid ?? TempConst.projectIdDev, showInDevice: event.showInDevice); filteredScenes = allScenes; diff --git a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart index 8e984ea..5817bad 100644 --- a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart +++ b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart @@ -2,6 +2,8 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:flutter/material.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart'; import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_state.dart'; @@ -10,6 +12,7 @@ import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/home_management_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; class DeviceManagerBloc extends Bloc { @@ -27,11 +30,16 @@ class DeviceManagerBloc extends Bloc { static List? allCategories; - Future _onFetchAllDevices(FetchAllDevices event, Emitter emit) async { + Future _onFetchAllDevices( + FetchAllDevices event, Emitter emit) async { emit(state.copyWith(loading: true)); try { - final allDevices = await HomeManagementAPI.fetchDevicesByUnitId(); - emit(state.copyWith(devices: _getOnlyImplementedDevices(allDevices), loading: false)); + Project? project = HomeCubit.getInstance().project; + + final allDevices = await HomeManagementAPI.fetchDevicesByUnitId( + project?.uuid ?? TempConst.projectIdDev); + emit(state.copyWith( + devices: _getOnlyImplementedDevices(allDevices), loading: false)); } catch (e) { emit(state.copyWith(error: e.toString(), loading: false)); } @@ -41,26 +49,31 @@ class DeviceManagerBloc extends Bloc { FetchDevicesByRoomId event, Emitter emit) async { emit(state.copyWith(loading: true)); try { - final devices = await DevicesAPI.getDevicesByRoomId( - communityUuid: event.unit.community.uuid, - spaceUuid: event.unit.id, - roomId: event.roomId, - ); + Project? project = HomeCubit.getInstance().project; - emit(state.copyWith(devices: _getOnlyImplementedDevices(devices), loading: false)); + final devices = await DevicesAPI.getDevicesByRoomId( + communityUuid: event.unit.community.uuid, + spaceUuid: event.unit.id, + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); + + emit(state.copyWith( + devices: _getOnlyImplementedDevices(devices), loading: false)); } catch (e) { emit(state.copyWith(error: e.toString(), loading: false)); } } - void _onSelectCategory(SelectCategory event, Emitter emit) { + void _onSelectCategory( + SelectCategory event, Emitter emit) { for (var i = 0; i < allCategories!.length; i++) { allCategories![i].isSelected = i == event.index; } emit(state.copyWith(categoryChanged: true)); } - void _onUnselectAllCategories(UnselectAllCategories event, Emitter emit) { + void _onUnselectAllCategories( + UnselectAllCategories event, Emitter emit) { for (var category in allCategories!) { category.isSelected = false; } @@ -104,7 +117,8 @@ class DeviceManagerBloc extends Bloc { _updateDevicesStatus(category, emit); } - void _onTurnOnOffDevice(TurnOnOffDevice event, Emitter emit) { + void _onTurnOnOffDevice( + TurnOnOffDevice event, Emitter emit) { var device = event.device; device.isOnline = !device.isOnline!; DevicesCategoryModel category = allCategories!.firstWhere((category) { @@ -127,7 +141,8 @@ class DeviceManagerBloc extends Bloc { emit(state.copyWith(categoryChanged: true)); // Set category changed state } - void _updateDevicesStatus(DevicesCategoryModel category, Emitter emit) { + void _updateDevicesStatus( + DevicesCategoryModel category, Emitter emit) { if (category.devices != null && category.devices!.isNotEmpty) { bool? tempStatus = category.devices![0].isOnline; for (var device in category.devices!) { @@ -147,7 +162,8 @@ class DeviceManagerBloc extends Bloc { try { final deviceFunctions = await DevicesAPI.deviceFunctions(event.deviceId); - emit(state.copyWith(functionsLoading: false, deviceFunctions: deviceFunctions)); + emit(state.copyWith( + functionsLoading: false, deviceFunctions: deviceFunctions)); } catch (e) { emit(state.copyWith(functionsLoading: false, error: e.toString())); } diff --git a/lib/features/devices/bloc/device_settings_bloc/device_scene_bloc.dart b/lib/features/devices/bloc/device_settings_bloc/device_scene_bloc.dart index 4c91650..fb03dc0 100644 --- a/lib/features/devices/bloc/device_settings_bloc/device_scene_bloc.dart +++ b/lib/features/devices/bloc/device_settings_bloc/device_scene_bloc.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/bloc/device_settings_bloc/device_scene_event.dart'; import 'package:syncrow_app/features/devices/bloc/device_settings_bloc/device_scene_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; @@ -18,6 +19,7 @@ import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/home_management_api.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; class DeviceSettingBloc extends Bloc { @@ -349,13 +351,20 @@ class DeviceSettingBloc extends Bloc { AssignRoomEvent event, Emitter emit) async { try { emit(DeviceSettingLoadingState()); + Project? project = HomeCubit.getInstance().project; + if (_hasSelectionChanged) { await HomeManagementAPI.assignDeviceToRoom( - event.unit.community.uuid, event.unit.id, event.roomId, deviceId); + event.unit.community.uuid, + event.unit.id, + event.roomId, + deviceId, + project?.uuid ?? TempConst.projectIdDev); final devicesList = await DevicesAPI.getDevicesByRoomId( communityUuid: event.unit.community.uuid, spaceUuid: event.unit.id, - roomId: event.roomId); + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); List allDevicesIds = []; allDevices.forEach((element) { allDevicesIds.add(element.uuid!); @@ -375,8 +384,12 @@ class DeviceSettingBloc extends Bloc { FetchRoomsEvent event, Emitter emit) async { try { emit(DeviceSettingLoadingState()); + Project? project = HomeCubit.getInstance().project; + roomsList = await SpacesAPI.getSubSpaceBySpaceId( - event.unit.community.uuid, event.unit.id); + event.unit.community.uuid, + event.unit.id, + project?.uuid ?? TempConst.projectIdDev); emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList)); } catch (e) { emit( diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 2949072..888b941 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/app_layout/model/space_model.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/model/device_category_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; @@ -19,6 +20,7 @@ import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/home_management_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/constants/temp_const.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; part 'devices_state.dart'; @@ -309,11 +311,14 @@ class DevicesCubit extends Cubit { .subspaces .indexWhere((element) => element.id == roomId); try { + Project? project = HomeCubit.getInstance().project; + HomeCubit.getInstance().selectedSpace!.subspaces[roomIndex].devices = await DevicesAPI.getDevicesByRoomId( communityUuid: unit!.community.uuid, spaceUuid: unit.id, - roomId: roomId); + roomId: roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); } catch (e) { emitSafe(GetDevicesError(e.toString())); return; @@ -410,10 +415,12 @@ class DevicesCubit extends Cubit { Future fetchAllDevices(SpaceModel? unit) async { emitSafe(GetDevicesLoading()); try { + Project? project = HomeCubit.getInstance().project; + final devices = await DevicesAPI.getAllDevices( - communityUuid: unit!.community.uuid, - spaceUuid: unit.id, - ); + communityUuid: unit!.community.uuid, + spaceUuid: unit.id, + projectId: project?.uuid ?? TempConst.projectIdDev); allDevices = devices; emitSafe(GetDevicesSuccess(allDevices)); } catch (e) { diff --git a/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart b/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart index d3069f7..7407467 100644 --- a/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart +++ b/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart @@ -1,6 +1,8 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart'; import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; @@ -14,6 +16,7 @@ import 'package:syncrow_app/features/devices/model/subspace_model.dart'; import 'package:syncrow_app/features/scene/model/scenes_model.dart'; import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/scene_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; class FourSceneBloc extends Bloc { @@ -299,9 +302,11 @@ class FourSceneBloc extends Bloc { LoadScenes event, Emitter emit) async { emit(FourSceneLoadingState()); try { + Project? project = HomeCubit.getInstance().project; + if (event.unitId.isNotEmpty) { allScenes = await SceneApi.getScenesByUnitId( - event.unitId, event.unit.community.uuid, + event.unitId, event.unit.community.uuid, project?.uuid ?? TempConst.projectIdDev, showInDevice: event.showInDevice); filteredScenes = allScenes; diff --git a/lib/features/devices/bloc/sos_bloc/sos_bloc.dart b/lib/features/devices/bloc/sos_bloc/sos_bloc.dart index 63082fa..0b0d028 100644 --- a/lib/features/devices/bloc/sos_bloc/sos_bloc.dart +++ b/lib/features/devices/bloc/sos_bloc/sos_bloc.dart @@ -5,6 +5,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/app_layout/model/community_model.dart'; import 'package:syncrow_app/features/app_layout/model/space_model.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart'; import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; @@ -19,6 +20,7 @@ import 'package:syncrow_app/navigation/routing_constants.dart'; import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/home_management_api.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; class SosBloc extends Bloc { @@ -184,8 +186,12 @@ class SosBloc extends Bloc { FetchRoomsEvent event, Emitter emit) async { try { emit(SosLoadingState()); + Project? project = HomeCubit.getInstance().project; + roomsList = await SpacesAPI.getSubSpaceBySpaceId( - event.unit.community.uuid, event.unit.id); + event.unit.community.uuid, + event.unit.id, + project?.uuid ?? TempConst.projectIdDev); emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList)); } catch (e) { emit(const SosFailedState(errorMessage: 'Something went wrong')); @@ -223,13 +229,19 @@ class SosBloc extends Bloc { void _assignDevice(AssignRoomEvent event, Emitter emit) async { try { emit(SosLoadingState()); + Project? project = HomeCubit.getInstance().project; await HomeManagementAPI.assignDeviceToRoom( - event.unit.community.uuid, event.unit.id, event.roomId, sosId); + event.unit.community.uuid, + event.unit.id, + event.roomId, + sosId, + project?.uuid ?? TempConst.projectIdDev); final devicesList = await DevicesAPI.getDevicesByRoomId( communityUuid: event.unit.community.uuid, spaceUuid: event.unit.id, - roomId: event.roomId); + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); List allDevicesIds = []; @@ -249,13 +261,16 @@ class SosBloc extends Bloc { void _unassignDevice(UnassignRoomEvent event, Emitter emit) async { try { Map roomDevicesId = {}; + Project? project = HomeCubit.getInstance().project; + emit(SosLoadingState()); await HomeManagementAPI.unAssignDeviceToRoom( - event.unit.community.uuid, event.unit.id, event.roomId, sosId); + event.unit.community.uuid, event.unit.id, event.roomId, sosId, project?.uuid ?? TempConst.projectIdDev); final devicesList = await DevicesAPI.getDevicesByRoomId( communityUuid: event.unit.community.uuid, spaceUuid: event.unit.id, - roomId: event.roomId); + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); List allDevicesIds = []; diff --git a/lib/features/menu/bloc/create_unit_bloc/create_unit_bloc.dart b/lib/features/menu/bloc/create_unit_bloc/create_unit_bloc.dart index 23a1e59..fad0ea4 100644 --- a/lib/features/menu/bloc/create_unit_bloc/create_unit_bloc.dart +++ b/lib/features/menu/bloc/create_unit_bloc/create_unit_bloc.dart @@ -1,10 +1,12 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/auth/model/user_model.dart'; import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_event.dart'; import 'package:syncrow_app/features/menu/bloc/create_unit_bloc/create_unit_state.dart'; import 'package:syncrow_app/services/api/home_creation_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; import 'package:syncrow_app/utils/helpers/snack_bar.dart'; class CreateUnitBloc extends Bloc { @@ -239,8 +241,13 @@ Future _createNewRoom( required String communityId}) async { try { Map body = {'subspaceName': roomName}; + Project? project = HomeCubit.getInstance().project; + final response = await HomeCreation.createRoom( - communityId: communityId, spaceId: unitId, body: body); + communityId: communityId, + spaceId: unitId, + body: body, + projectId: project?.uuid ?? TempConst.projectIdDev); // if (response['data']['uuid'] != '') { // final result = await _assignToRoom(roomId: response['data']['uuid'], userId: userId); diff --git a/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart b/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart index bd6b653..0883eb9 100644 --- a/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart +++ b/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart @@ -1,5 +1,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_event.dart'; import 'package:syncrow_app/features/menu/bloc/manage_unit_bloc/manage_unit_state.dart'; @@ -7,6 +8,7 @@ import 'package:syncrow_app/services/api/devices_api.dart'; import 'package:syncrow_app/services/api/home_creation_api.dart'; import 'package:syncrow_app/services/api/home_management_api.dart'; import 'package:syncrow_app/services/api/spaces_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; class ManageUnitBloc extends Bloc { List allDevices = []; @@ -24,8 +26,12 @@ class ManageUnitBloc extends Bloc { FetchRoomsEvent event, Emitter emit) async { try { emit(LoadingState()); + Project? project = HomeCubit.getInstance().project; + final roomsList = await SpacesAPI.getSubSpaceBySpaceId( - event.unit.community.uuid, event.unit.id); + event.unit.community.uuid, + event.unit.id, + project?.uuid ?? TempConst.projectIdDev); emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList)); } catch (e) { emit(const ErrorState(message: 'Something went wrong')); @@ -37,11 +43,14 @@ class ManageUnitBloc extends Bloc { FetchDevicesByRoomIdEvent event, Emitter emit) async { try { Map roomDevicesId = {}; + Project? project = HomeCubit.getInstance().project; + emit(LoadingState()); final devicesList = await DevicesAPI.getDevicesByRoomId( communityUuid: event.unit.community.uuid, spaceUuid: event.unit.id, - roomId: event.roomId); + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); allDevices = await HomeManagementAPI.fetchDevicesByUserId(); List allDevicesIds = []; @@ -72,14 +81,21 @@ class ManageUnitBloc extends Bloc { AssignRoomEvent event, Emitter emit) async { try { Map roomDevicesId = {}; + Project? project = HomeCubit.getInstance().project; + emit(LoadingState()); - + await HomeManagementAPI.assignDeviceToRoom( - event.unit.community.uuid, event.unit.id, event.roomId, event.deviceId); + event.unit.community.uuid, + event.unit.id, + event.roomId, + event.deviceId, + project?.uuid ?? TempConst.projectIdDev); final devicesList = await DevicesAPI.getDevicesByRoomId( communityUuid: event.unit.community.uuid, spaceUuid: event.unit.id, - roomId: event.roomId); + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); List allDevicesIds = []; @@ -105,19 +121,25 @@ class ManageUnitBloc extends Bloc { } } - void _unassignDevice( UnassignRoomEvent event, Emitter emit) async { try { Map roomDevicesId = {}; + Project? project = HomeCubit.getInstance().project; + emit(LoadingState()); - + await HomeManagementAPI.unAssignDeviceToRoom( - event.unit.community.uuid, event.unit.id, event.roomId, event.deviceId); + event.unit.community.uuid, + event.unit.id, + event.roomId, + event.deviceId, + project?.uuid ?? TempConst.projectIdDev); final devicesList = await DevicesAPI.getDevicesByRoomId( communityUuid: event.unit.community.uuid, spaceUuid: event.unit.id, - roomId: event.roomId); + roomId: event.roomId, + projectId: project?.uuid ?? TempConst.projectIdDev); List allDevicesIds = []; @@ -143,18 +165,22 @@ class ManageUnitBloc extends Bloc { } } - _addNewRoom(AddNewRoom event, Emitter emit) async { Map body = {'subspaceName': event.roomName}; try { emit(LoadingState()); + Project? project = HomeCubit.getInstance().project; + final response = await HomeCreation.createRoom( communityId: event.unit.community.uuid, spaceId: event.unit.id, - body: body); + body: body, + projectId: project?.uuid ?? TempConst.projectIdDev); if (response['data']['uuid'] != '') { final roomsList = await SpacesAPI.getSubSpaceBySpaceId( - event.unit.community.uuid, event.unit.id); + event.unit.community.uuid, + event.unit.id, + project?.uuid ?? TempConst.projectIdDev); allDevices = await HomeManagementAPI.fetchDevicesByUserId(); emit(FetchRoomsState(devicesList: allDevices, roomsList: roomsList)); await HomeCubit.getInstance().fetchUnitsByUserId(); diff --git a/lib/features/menu/bloc/profile_bloc/profile_bloc.dart b/lib/features/menu/bloc/profile_bloc/profile_bloc.dart index c01a5c5..c7c56d3 100644 --- a/lib/features/menu/bloc/profile_bloc/profile_bloc.dart +++ b/lib/features/menu/bloc/profile_bloc/profile_bloc.dart @@ -23,8 +23,8 @@ class ProfileBloc extends Bloc { String timeZoneSelected = ''; String regionSelected = ''; final TextEditingController searchController = TextEditingController(); - final TextEditingController nameController = - TextEditingController(text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}'); + final TextEditingController nameController = TextEditingController( + text: '${HomeCubit.user!.firstName} ${HomeCubit.user!.lastName}'); List allRegions = []; List allTimeZone = []; @@ -77,10 +77,13 @@ class ProfileBloc extends Bloc { emit(NameEditingState(editName: editName)); } - void _fetchUserInfo(InitialProfileEvent event, Emitter emit) async { + void _fetchUserInfo( + InitialProfileEvent event, Emitter emit) async { try { emit(LoadingInitialState()); HomeCubit.user = await ProfileApi().fetchUserInfo(HomeCubit.user!.uuid); + HomeCubit.getInstance().project = HomeCubit.user?.project; + emit(SaveState()); } catch (e) { emit(FailedState(errorMessage: e.toString())); @@ -88,7 +91,8 @@ class ProfileBloc extends Bloc { } } - Future _fetchTimeZone(TimeZoneInitialEvent event, Emitter emit) async { + Future _fetchTimeZone( + TimeZoneInitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { allTimeZone = await ProfileApi.fetchTimeZone(); @@ -100,7 +104,8 @@ class ProfileBloc extends Bloc { } } - Future selectTimeZone(SelectTimeZoneEvent event, Emitter emit) async { + Future selectTimeZone( + SelectTimeZoneEvent event, Emitter emit) async { try { emit(LoadingInitialState()); timeZoneSelected = event.val; @@ -112,7 +117,8 @@ class ProfileBloc extends Bloc { } } - Future selectRegion(SelectRegionEvent event, Emitter emit) async { + Future selectRegion( + SelectRegionEvent event, Emitter emit) async { try { emit(LoadingInitialState()); await ProfileApi.saveRegion(regionUuid: event.val); @@ -124,7 +130,8 @@ class ProfileBloc extends Bloc { } } - Future searchRegion(SearchRegionEvent event, Emitter emit) async { + Future searchRegion( + SearchRegionEvent event, Emitter emit) async { emit(LoadingInitialState()); final query = event.query.toLowerCase(); if (allRegions.isEmpty) { @@ -140,7 +147,8 @@ class ProfileBloc extends Bloc { } } - Future searchTimeZone(SearchTimeZoneEvent event, Emitter emit) async { + Future searchTimeZone( + SearchTimeZoneEvent event, Emitter emit) async { emit(LoadingInitialState()); final query = event.query.toLowerCase(); if (allTimeZone.isEmpty) { @@ -156,7 +164,8 @@ class ProfileBloc extends Bloc { } } - void _fetchRegion(RegionInitialEvent event, Emitter emit) async { + void _fetchRegion( + RegionInitialEvent event, Emitter emit) async { try { emit(LoadingInitialState()); allRegions = await ProfileApi.fetchRegion(); @@ -166,7 +175,8 @@ class ProfileBloc extends Bloc { } } - Future _selectImage(SelectImageEvent event, Emitter emit) async { + Future _selectImage( + SelectImageEvent event, Emitter emit) async { try { if (await _requestPermission()) { emit(ChangeImageState()); @@ -283,7 +293,8 @@ class ProfileBloc extends Bloc { } return false; } else { - SharedPreferences sharedPreferences = await SharedPreferences.getInstance(); + SharedPreferences sharedPreferences = + await SharedPreferences.getInstance(); bool firstClick = sharedPreferences.getBool('firstPermission') ?? true; await sharedPreferences.setBool('firstPermission', false); if (firstClick == false) { diff --git a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart index 4837d32..97b3ac6 100644 --- a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart +++ b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart @@ -2,9 +2,12 @@ import 'dart:async'; import 'package:equatable/equatable.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; +import 'package:syncrow_app/features/auth/model/project_model.dart'; import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart'; import 'package:syncrow_app/features/scene/model/scenes_model.dart'; import 'package:syncrow_app/services/api/scene_api.dart'; +import 'package:syncrow_app/utils/constants/temp_const.dart'; part 'scene_state.dart'; @@ -23,9 +26,11 @@ class SceneBloc extends Bloc { emit(SceneLoading()); try { + Project? project = HomeCubit.getInstance().project; + if (event.unitId.isNotEmpty) { - scenes = await SceneApi.getScenesByUnitId( - event.unitId, event.unit.community.uuid, + scenes = await SceneApi.getScenesByUnitId(event.unitId, + event.unit.community.uuid, project?.uuid ?? TempConst.projectIdDev, showInDevice: event.showInDevice); emit(SceneLoaded(scenes, automationList)); } else { diff --git a/lib/services/api/devices_api.dart b/lib/services/api/devices_api.dart index b9b27b5..9475ddf 100644 --- a/lib/services/api/devices_api.dart +++ b/lib/services/api/devices_api.dart @@ -219,13 +219,14 @@ class DevicesAPI { required String communityUuid, required String spaceUuid, required String roomId, + required String projectId, }) async { try { final String path = ApiEndpoints.deviceByRoom .replaceAll('{communityUuid}', communityUuid) .replaceAll('{spaceUuid}', spaceUuid) .replaceAll('{subSpaceUuid}', roomId) - .replaceAll('{projectUuid}', TempConst.projectIdDev); + .replaceAll('{projectUuid}', projectId); final response = await _httpService.get( path: path, @@ -564,12 +565,13 @@ class DevicesAPI { static Future> getAllDevices({ required String communityUuid, required String spaceUuid, + required String projectId, }) async { try { final String path = ApiEndpoints.getAllDevices .replaceAll('{communityUuid}', communityUuid) .replaceAll('{spaceUuid}', spaceUuid) - .replaceAll('{projectUuid}', TempConst.projectIdDev); + .replaceAll('{projectUuid}', projectId); final response = await _httpService.get( path: path, diff --git a/lib/services/api/home_creation_api.dart b/lib/services/api/home_creation_api.dart index 9d3fd13..4f7eb07 100644 --- a/lib/services/api/home_creation_api.dart +++ b/lib/services/api/home_creation_api.dart @@ -145,12 +145,13 @@ class HomeCreation { required String communityId, required String spaceId, required Map body, + required String projectId }) async { try { final fullPath = ApiEndpoints.addSubSpace .replaceAll('{communityUuid}', communityId) .replaceAll('{spaceUuid}', spaceId) - .replaceAll('{projectUuid}', TempConst.projectIdDev); + .replaceAll('{projectUuid}', projectId); final response = await _httpService.post( path: fullPath, body: body, diff --git a/lib/services/api/home_management_api.dart b/lib/services/api/home_management_api.dart index abeff8e..8febf4b 100644 --- a/lib/services/api/home_management_api.dart +++ b/lib/services/api/home_management_api.dart @@ -27,7 +27,7 @@ class HomeManagementAPI { return list; } - static Future> fetchDevicesByUnitId() async { + static Future> fetchDevicesByUnitId(String projectUuid) async { List list = []; try { @@ -40,7 +40,7 @@ class HomeManagementAPI { final path = ApiEndpoints.spaceDevices .replaceAll('{communityUuid}', communityUuid) .replaceAll('{spaceUuid}', spaceUuid) - .replaceAll('{projectUuid}', TempConst.projectIdDev); + .replaceAll('{projectUuid}', projectUuid); await _httpService.get( path: path, @@ -63,11 +63,11 @@ class HomeManagementAPI { } static Future> assignDeviceToRoom(String communityId, - String spaceId, String subSpaceId, String deviceId) async { + String spaceId, String subSpaceId, String deviceId, String projectId) async { try { final response = await _httpService.post( path: ApiEndpoints.assignDeviceToRoom - .replaceAll('{projectUuid}', TempConst.projectIdDev) + .replaceAll('{projectUuid}', projectId) .replaceAll('{communityUuid}', communityId) .replaceAll('{spaceUuid}', spaceId) .replaceAll('{subSpaceUuid}', subSpaceId) @@ -83,7 +83,7 @@ class HomeManagementAPI { } static Future> unAssignDeviceToRoom(String communityId, - String spaceId, String subSpaceId, String deviceId) async { + String spaceId, String subSpaceId, String deviceId, String projectId) async { try { final response = await _httpService.delete( path: ApiEndpoints.assignDeviceToRoom @@ -91,7 +91,7 @@ class HomeManagementAPI { .replaceAll('{spaceUuid}', spaceId) .replaceAll('{subSpaceUuid}', subSpaceId) .replaceAll('{deviceUuid}', deviceId) - .replaceAll('{projectUuid}', TempConst.projectIdDev), + .replaceAll('{projectUuid}', projectId), expectedResponseModel: (json) { return json; }, diff --git a/lib/services/api/scene_api.dart b/lib/services/api/scene_api.dart index 0281417..ce4a5ae 100644 --- a/lib/services/api/scene_api.dart +++ b/lib/services/api/scene_api.dart @@ -50,14 +50,14 @@ class SceneApi { //get scene by unit id static Future> getScenesByUnitId( - String unitId, String communityId, + String unitId, String communityId, String projectId, {showInDevice = false}) async { try { final response = await _httpService.get( path: ApiEndpoints.getUnitScenes .replaceAll('{spaceUuid}', unitId) .replaceAll('{communityUuid}', communityId) - .replaceAll('{projectUuid}', TempConst.projectIdDev), + .replaceAll('{projectUuid}', projectId), queryParameters: {'showInHomePage': showInDevice}, showServerMessage: false, expectedResponseModel: (json) { diff --git a/lib/services/api/spaces_api.dart b/lib/services/api/spaces_api.dart index 3864f60..7ab3e19 100644 --- a/lib/services/api/spaces_api.dart +++ b/lib/services/api/spaces_api.dart @@ -32,13 +32,13 @@ class SpacesAPI { } static Future> getSubSpaceBySpaceId( - String communityId, String spaceId) async { + String communityId, String spaceId, String projectId) async { try { // Construct the API path final path = ApiEndpoints.listSubspace .replaceFirst('{communityUuid}', communityId) .replaceFirst('{spaceUuid}', spaceId) - .replaceAll('{projectUuid}', TempConst.projectIdDev); + .replaceAll('{projectUuid}', projectId); final response = await _httpService.get( path: path, @@ -66,12 +66,12 @@ class SpacesAPI { //factory/reset/{deviceUuid} static Future generateInvitationCode( - String unitId, String communityId) async { + String unitId, String communityId, String projectId) async { final response = await _httpService.post( path: ApiEndpoints.invitationCode .replaceAll('{unitUuid}', unitId) .replaceAll('{communityUuid}', communityId) - .replaceAll('{projectUuid}', TempConst.projectIdDev), + .replaceAll('{projectUuid}', projectId), showServerMessage: false, expectedResponseModel: (json) { if (json != null && json['data'] != null) { From 450b773921ea9ba76195fd51df10f594052424ee Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Thu, 20 Feb 2025 04:13:37 +0300 Subject: [PATCH 6/9] set default values in the devices models instead of late, and fixed issues in the AC bloc --- .../devices/bloc/acs_bloc/acs_bloc.dart | 86 +++++++------------ lib/features/devices/model/ac_model.dart | 18 ++-- .../devices/model/ceiling_sensor_model.dart | 6 +- lib/features/devices/model/curtain_model.dart | 6 +- .../devices/model/device_info_model.dart | 2 - .../devices/model/door_sensor_model.dart | 19 ++-- .../devices/model/garage_door_model.dart | 18 ++-- .../devices/model/one_gang_model.dart | 18 ++-- .../devices/model/one_touch_model.dart | 23 ++--- .../devices/model/six_scene_model.dart | 16 ++-- .../devices/model/smart_door_model.dart | 34 ++++---- lib/features/devices/model/sos_model.dart | 4 +- .../devices/view/widgets/ACs/acs_list.dart | 2 +- pubspec.yaml | 2 +- 14 files changed, 106 insertions(+), 148 deletions(-) diff --git a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart index 95de36f..b88cf3b 100644 --- a/lib/features/devices/bloc/acs_bloc/acs_bloc.dart +++ b/lib/features/devices/bloc/acs_bloc/acs_bloc.dart @@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_event.dart'; import 'package:syncrow_app/features/devices/bloc/acs_bloc/acs_state.dart'; -import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/ac_model.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; @@ -28,7 +27,7 @@ class ACsBloc extends Bloc { bool allAcsPage = false; bool allAcsOn = true; bool allTempSame = true; - int globalTemp = 25; + int globalTemp = 250; Timer? _timer; ACsBloc({required this.acId}) : super(AcsInitialState()) { @@ -69,8 +68,7 @@ class ACsBloc extends Bloc { for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); } - deviceStatus = - AcStatusModel.fromJson(response['productUuid'], statusModelList); + deviceStatus = AcStatusModel.fromJson(response['productUuid'], statusModelList); emit(GetAcStatusState(acStatusModel: deviceStatus)); Future.delayed(const Duration(milliseconds: 500)); // _listenToChanges(); @@ -83,22 +81,18 @@ class ACsBloc extends Bloc { _listenToChanges() { try { - DatabaseReference ref = - FirebaseDatabase.instance.ref('device-status/$acId'); + DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$acId'); Stream stream = ref.onValue; stream.listen((DatabaseEvent event) { - Map usersMap = - event.snapshot.value as Map; + Map usersMap = event.snapshot.value as Map; List statusList = []; usersMap['status'].forEach((element) { - statusList - .add(StatusModel(code: element['code'], value: element['value'])); + statusList.add(StatusModel(code: element['code'], value: element['value'])); }); - deviceStatus = - AcStatusModel.fromJson(usersMap['productUuid'], statusList); + deviceStatus = AcStatusModel.fromJson(usersMap['productUuid'], statusList); add(AcUpdated()); }); } catch (_) {} @@ -115,14 +109,12 @@ class ACsBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', 'AC'); for (int i = 0; i < devicesList.length; i++) { - var response = - await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); + var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); List statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); } - deviceStatusList.add( - AcStatusModel.fromJson(response['productUuid'], statusModelList)); + deviceStatusList.add(AcStatusModel.fromJson(devicesList[i].uuid ?? '', statusModelList)); } _setAllAcsTempsAndSwitches(); } @@ -132,7 +124,7 @@ class ACsBloc extends Bloc { if (allAcsPage) { emit(AcsLoadingState()); for (AcStatusModel ac in deviceStatusList) { - if (ac.uuid == event.productId) { + if (ac.uuid == event.deviceId) { ac.acSwitch = acSwitchValue; } } @@ -145,8 +137,7 @@ class ACsBloc extends Bloc { emit(AcModifyingState(acStatusModel: deviceStatus)); } - await _runDeBouncerForOneDevice( - deviceId: event.deviceId, code: 'switch', value: acSwitchValue); + await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'switch', value: acSwitchValue); } void _changeAllAcSwitch(ChangeAllSwitch event, Emitter emit) async { @@ -207,8 +198,7 @@ class ACsBloc extends Bloc { deviceStatus.childLock = lockValue; emit(AcModifyingState(acStatusModel: deviceStatus)); - await _runDeBouncerForOneDevice( - deviceId: acId, code: 'child_lock', value: lockValue); + await _runDeBouncerForOneDevice(deviceId: acId, code: 'child_lock', value: lockValue); } void _increaseCoolTo(IncreaseCoolToTemp event, Emitter emit) async { @@ -224,7 +214,7 @@ class ACsBloc extends Bloc { if (allAcsPage) { emit(AcsLoadingState()); for (AcStatusModel ac in deviceStatusList) { - if (ac.uuid == event.productId) { + if (ac.uuid == event.deviceId) { ac.tempSet = value; } } @@ -236,8 +226,7 @@ class ACsBloc extends Bloc { emit(AcModifyingState(acStatusModel: deviceStatus)); } - await _runDeBouncerForOneDevice( - deviceId: event.deviceId, code: 'temp_set', value: value); + await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value); } void _decreaseCoolTo(DecreaseCoolToTemp event, Emitter emit) async { @@ -253,7 +242,7 @@ class ACsBloc extends Bloc { if (allAcsPage) { emit(AcsLoadingState()); for (AcStatusModel ac in deviceStatusList) { - if (ac.uuid == event.productId) { + if (ac.uuid == event.deviceId) { ac.tempSet = value; } } @@ -265,8 +254,7 @@ class ACsBloc extends Bloc { emit(AcModifyingState(acStatusModel: deviceStatus)); } - await _runDeBouncerForOneDevice( - deviceId: event.deviceId, code: 'temp_set', value: value); + await _runDeBouncerForOneDevice(deviceId: event.deviceId, code: 'temp_set', value: value); } void _changeAcMode(ChangeAcMode event, Emitter emit) async { @@ -274,7 +262,7 @@ class ACsBloc extends Bloc { if (allAcsPage) { emit(AcsLoadingState()); for (AcStatusModel ac in deviceStatusList) { - if (ac.uuid == event.productId) { + if (ac.uuid == event.deviceId) { ac.modeString = getACModeString(tempMode); ac.acMode = AcStatusModel.getACMode(getACModeString(tempMode)); } @@ -288,9 +276,7 @@ class ACsBloc extends Bloc { } await _runDeBouncerForOneDevice( - deviceId: event.deviceId, - code: 'mode', - value: getACModeString(tempMode)); + deviceId: event.deviceId, code: 'mode', value: getACModeString(tempMode)); } void _changeFanSpeed(ChangeFanSpeed event, Emitter emit) async { @@ -301,25 +287,21 @@ class ACsBloc extends Bloc { if (allAcsPage) { emit(AcsLoadingState()); for (AcStatusModel ac in deviceStatusList) { - if (ac.uuid == event.productId) { + if (ac.uuid == event.deviceId) { ac.fanSpeedsString = getNextFanSpeedKey(fanSpeed); - ac.acFanSpeed = - AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed)); + ac.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed)); } } _emitAcsStatus(emit); } else { emit(AcChangeLoading(acStatusModel: deviceStatus)); deviceStatus.fanSpeedsString = getNextFanSpeedKey(fanSpeed); - deviceStatus.acFanSpeed = - AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed)); + deviceStatus.acFanSpeed = AcStatusModel.getFanSpeed(getNextFanSpeedKey(fanSpeed)); emit(AcModifyingState(acStatusModel: deviceStatus)); } await _runDeBouncerForOneDevice( - deviceId: event.deviceId, - code: 'level', - value: getNextFanSpeedKey(fanSpeed)); + deviceId: event.deviceId, code: 'level', value: getNextFanSpeedKey(fanSpeed)); } String getACModeString(TempModes value) { @@ -338,17 +320,15 @@ class ACsBloc extends Bloc { allAcsOn = true; allTempSame = true; if (deviceStatusList.isNotEmpty) { - int temp = deviceStatusList[0].tempSet; - deviceStatusList.firstWhere((element) { + int temp = deviceStatusList.first.tempSet; + for (var element in deviceStatusList) { if (!element.acSwitch) { allAcsOn = false; } if (element.tempSet != temp) { allTempSame = false; } - - return true; - }); + } if (allTempSame) { globalTemp = temp; } @@ -364,8 +344,7 @@ class ACsBloc extends Bloc { for (int i = 0; i < deviceStatusList.length; i++) { try { await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: devicesList[i].uuid, code: code, value: value), + DeviceControlModel(deviceId: devicesList[i].uuid, code: code, value: value), devicesList[i].uuid ?? ''); } catch (_) { await Future.delayed(const Duration(milliseconds: 500)); @@ -387,10 +366,7 @@ class ACsBloc extends Bloc { _timer = Timer(const Duration(seconds: 1), () async { try { final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: allAcsPage ? deviceId : acId, - code: code, - value: value), + DeviceControlModel(deviceId: allAcsPage ? deviceId : acId, code: code, value: value), allAcsPage ? deviceId : acId); if (!response['success']) { @@ -407,8 +383,7 @@ class ACsBloc extends Bloc { if (value >= 20 && value <= 30) { return true; } else { - emit(const AcsFailedState( - errorMessage: 'The temperature must be between 20 and 30')); + emit(const AcsFailedState(errorMessage: 'The temperature must be between 20 and 30')); emit(GetAllAcsStatusState( allAcsStatues: deviceStatusList, allAcs: devicesList, @@ -434,9 +409,7 @@ class ACsBloc extends Bloc { try { seconds = event.seconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: acId, code: 'countdown_time', value: event.duration), - acId); + DeviceControlModel(deviceId: acId, code: 'countdown_time', value: event.duration), acId); if (response['success'] ?? false) { deviceStatus.countdown1 = seconds; @@ -463,8 +436,7 @@ class ACsBloc extends Bloc { for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); } - deviceStatus = - AcStatusModel.fromJson(response['productUuid'], statusModelList); + deviceStatus = AcStatusModel.fromJson(response['productUuid'], statusModelList); deviceStatus.countdown1; var duration; if (deviceStatus.countdown1 == 5) { diff --git a/lib/features/devices/model/ac_model.dart b/lib/features/devices/model/ac_model.dart index 677c414..6962c2a 100644 --- a/lib/features/devices/model/ac_model.dart +++ b/lib/features/devices/model/ac_model.dart @@ -27,24 +27,24 @@ class AcStatusModel { } factory AcStatusModel.fromJson(String id, List jsonList) { - late bool _acSwitch; - late String _mode; - late int _tempSet; - late int _currentTemp; - late String _fanSpeeds; - late int _countdown1; - late bool _childLock; + bool _acSwitch = false; + String _mode = ''; + int _tempSet = 210; + int _currentTemp = 210; + String _fanSpeeds = ''; + int _countdown1 = 0; + bool _childLock = false; 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; + _mode = jsonList[i].value ?? ''; } 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; + _fanSpeeds = jsonList[i].value ?? ''; } else if (jsonList[i].code == 'child_lock') { _childLock = jsonList[i].value ?? false; } else if (jsonList[i].code == 'countdown_time') { diff --git a/lib/features/devices/model/ceiling_sensor_model.dart b/lib/features/devices/model/ceiling_sensor_model.dart index b086038..e66e513 100644 --- a/lib/features/devices/model/ceiling_sensor_model.dart +++ b/lib/features/devices/model/ceiling_sensor_model.dart @@ -23,9 +23,9 @@ class CeilingSensorModel { required this.bodyMovement}); factory CeilingSensorModel.fromJson(List jsonList) { - late String _presenceState; - late int _sensitivity; - late String _checkingResult; + String _presenceState = 'none'; + int _sensitivity = 1; + String _checkingResult = ''; int _presenceRange = 1; int _sportsPara = 1; int _moving_max_dis = 0; diff --git a/lib/features/devices/model/curtain_model.dart b/lib/features/devices/model/curtain_model.dart index a8cf3e5..16f4203 100644 --- a/lib/features/devices/model/curtain_model.dart +++ b/lib/features/devices/model/curtain_model.dart @@ -10,11 +10,11 @@ class CurtainModel { }); factory CurtainModel.fromJson(List jsonList) { - late String _control; - late int _percent; + String _control = ''; + int _percent = 0; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'control') { - _control = jsonList[i].value ?? false; + _control = jsonList[i].value ?? ''; } if (jsonList[i].code == 'percent_control') { _percent = jsonList[i].value ?? 0; diff --git a/lib/features/devices/model/device_info_model.dart b/lib/features/devices/model/device_info_model.dart index 9c01d70..b3c1653 100644 --- a/lib/features/devices/model/device_info_model.dart +++ b/lib/features/devices/model/device_info_model.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - class DeviceInfoModel { final int activeTime; final String category; diff --git a/lib/features/devices/model/door_sensor_model.dart b/lib/features/devices/model/door_sensor_model.dart index 7ef8b1d..fa27287 100644 --- a/lib/features/devices/model/door_sensor_model.dart +++ b/lib/features/devices/model/door_sensor_model.dart @@ -1,27 +1,22 @@ - - - - import 'package:syncrow_app/features/devices/model/status_model.dart'; class DoorSensorModel { bool doorContactState; int batteryPercentage; - DoorSensorModel( - {required this.doorContactState, - required this.batteryPercentage, - }); + DoorSensorModel({ + required this.doorContactState, + required this.batteryPercentage, + }); factory DoorSensorModel.fromJson(List jsonList) { - late bool _doorContactState; - late int _batteryPercentage; - + bool _doorContactState = false; + int _batteryPercentage = 0; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'doorcontact_state') { _doorContactState = jsonList[i].value ?? false; - } else if (jsonList[i].code == 'battery_percentage') { + } else if (jsonList[i].code == 'battery_percentage') { _batteryPercentage = jsonList[i].value ?? 0; } } diff --git a/lib/features/devices/model/garage_door_model.dart b/lib/features/devices/model/garage_door_model.dart index 146523a..3bda7ae 100644 --- a/lib/features/devices/model/garage_door_model.dart +++ b/lib/features/devices/model/garage_door_model.dart @@ -24,15 +24,15 @@ class GarageDoorModel { }); factory GarageDoorModel.fromJson(List jsonList) { - late bool _switch1 = false; - late bool _doorContactState = false; - late int _countdown1 = 0; - late int _countdownAlarm = 0; - late String _doorControl1 = "closed"; - late bool _voiceControl1 = false; - late String _doorState1 = "closed"; - late int _batteryPercentage = 0; - late int _tr_timecon = 0; + bool _switch1 = false; + bool _doorContactState = false; + int _countdown1 = 0; + int _countdownAlarm = 0; + String _doorControl1 = "closed"; + bool _voiceControl1 = false; + String _doorState1 = "closed"; + int _batteryPercentage = 0; + int _tr_timecon = 0; for (var status in jsonList) { switch (status.code) { diff --git a/lib/features/devices/model/one_gang_model.dart b/lib/features/devices/model/one_gang_model.dart index 4e73231..a12fcf1 100644 --- a/lib/features/devices/model/one_gang_model.dart +++ b/lib/features/devices/model/one_gang_model.dart @@ -1,29 +1,27 @@ - import 'package:syncrow_app/features/devices/model/status_model.dart'; class OneGangModel { bool firstSwitch; int firstCountDown; - OneGangModel( - {required this.firstSwitch, - required this.firstCountDown, - }); + OneGangModel({ + required this.firstSwitch, + required this.firstCountDown, + }); factory OneGangModel.fromJson(List jsonList) { - late bool _switch; - late int _count; - + bool _switch = false; + int _count = 0; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'switch_1') { _switch = jsonList[i].value ?? false; - } else if (jsonList[i].code == 'countdown_1') { + } else if (jsonList[i].code == 'countdown_1') { _count = jsonList[i].value ?? 0; } } return OneGangModel( - firstSwitch: _switch, + firstSwitch: _switch, firstCountDown: _count, ); } diff --git a/lib/features/devices/model/one_touch_model.dart b/lib/features/devices/model/one_touch_model.dart index 34ea764..6ca95b2 100644 --- a/lib/features/devices/model/one_touch_model.dart +++ b/lib/features/devices/model/one_touch_model.dart @@ -1,5 +1,3 @@ - - import 'package:syncrow_app/features/devices/model/status_model.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; @@ -15,15 +13,14 @@ class OneTouchModel { required this.firstCountDown, required this.light_mode, required this.relay, - required this.relay_status_1 - }); + required this.relay_status_1}); factory OneTouchModel.fromJson(List jsonList) { - late bool _switch; - late int _count; - late String _relay; - late String _light_mode; - late String relay_status_1; + bool _switch = false; + int _count = 0; + String _relay = ''; + String _light_mode = ''; + String relay_status_1 = ''; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'switch_1') { @@ -41,10 +38,8 @@ class OneTouchModel { return OneTouchModel( firstSwitch: _switch, firstCountDown: _count, - light_mode: lightStatusExtension.fromString(_light_mode) , - relay: StatusExtension.fromString(_relay ) , - relay_status_1: StatusExtension.fromString(relay_status_1 ) - - ); + light_mode: lightStatusExtension.fromString(_light_mode), + relay: StatusExtension.fromString(_relay), + relay_status_1: StatusExtension.fromString(relay_status_1)); } } diff --git a/lib/features/devices/model/six_scene_model.dart b/lib/features/devices/model/six_scene_model.dart index c3c01b5..be697d6 100644 --- a/lib/features/devices/model/six_scene_model.dart +++ b/lib/features/devices/model/six_scene_model.dart @@ -22,14 +22,14 @@ class SixSceneModel { }); factory SixSceneModel.fromJson(List jsonList) { - late dynamic _scene_1; - late dynamic _scene_2; - late dynamic _scene_3; - late dynamic _scene_4; - late dynamic _scene_5; - late dynamic _scene_6; - late dynamic _scene_id_group_id; - late dynamic _switch_backlight; + dynamic _scene_1 = ''; + dynamic _scene_2 = ''; + dynamic _scene_3 = ''; + dynamic _scene_4 = ''; + dynamic _scene_5 = ''; + dynamic _scene_6 = ''; + dynamic _scene_id_group_id = 0; + dynamic _switch_backlight = false; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'scene_1') { diff --git a/lib/features/devices/model/smart_door_model.dart b/lib/features/devices/model/smart_door_model.dart index 2403941..a215d0c 100644 --- a/lib/features/devices/model/smart_door_model.dart +++ b/lib/features/devices/model/smart_door_model.dart @@ -39,23 +39,23 @@ class SmartDoorModel { required this.normalOpenSwitch}); factory SmartDoorModel.fromJson(List jsonList) { - late int _unlockFingerprint; - late int _unlockPassword; - late int _unlockTemporary; - late int _unlockCard; - late String _unlockAlarm; - late int _unlockRequest; - late int _residualElectricity; - late bool _reverseLock; - late int _unlockApp; - late bool _hijack; - late bool _doorbell; - late String _unlockOfflinePd; - late String _unlockOfflineClear; - late String _unlockDoubleKit; - late String _remoteNoPdSetkey; - late String _remoteNoDpKey; - late bool _normalOpenSwitch; + int _unlockFingerprint = 0; + int _unlockPassword = 0; + int _unlockTemporary = 0; + int _unlockCard = 0; + String _unlockAlarm = ''; + int _unlockRequest = 0; + int _residualElectricity = 0; + bool _reverseLock = false; + int _unlockApp = 0; + bool _hijack = false; + bool _doorbell = false; + String _unlockOfflinePd = ''; + String _unlockOfflineClear = ''; + String _unlockDoubleKit = ''; + String _remoteNoPdSetkey = ''; + String _remoteNoDpKey = ''; + bool _normalOpenSwitch = false; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'unlock_fingerprint') { diff --git a/lib/features/devices/model/sos_model.dart b/lib/features/devices/model/sos_model.dart index 7534b60..9ec0f33 100644 --- a/lib/features/devices/model/sos_model.dart +++ b/lib/features/devices/model/sos_model.dart @@ -10,8 +10,8 @@ class SosModel { }); factory SosModel.fromJson(List jsonList) { - late String _sosContactState; - late int _batteryPercentage; + String _sosContactState = ''; + int _batteryPercentage = 0; for (int i = 0; i < jsonList.length; i++) { if (jsonList[i].code == 'sos') { diff --git a/lib/features/devices/view/widgets/ACs/acs_list.dart b/lib/features/devices/view/widgets/ACs/acs_list.dart index 735bc9c..f1c81f4 100644 --- a/lib/features/devices/view/widgets/ACs/acs_list.dart +++ b/lib/features/devices/view/widgets/ACs/acs_list.dart @@ -31,7 +31,7 @@ class ACsList extends StatelessWidget { List devicesList = []; bool allOn = false; bool allTempSame = false; - int temperature = 20; + int temperature = 250; if (state is GetAllAcsStatusState) { devicesStatuesList = state.allAcsStatues; devicesList = state.allAcs; diff --git a/pubspec.yaml b/pubspec.yaml index 221c843..b60a986 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 1.0.18+55 +version: 1.0.27+64 environment: sdk: ">=3.0.6 <4.0.0" From 0b45d61b25b244604c5580b64c13db3c2512c225 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Thu, 20 Feb 2025 10:50:47 +0300 Subject: [PATCH 7/9] Fixed list issue in the manage home screen --- .../widgets/manage_home/manage_home_view.dart | 131 ++++++++---------- 1 file changed, 60 insertions(+), 71 deletions(-) diff --git a/lib/features/menu/view/widgets/manage_home/manage_home_view.dart b/lib/features/menu/view/widgets/manage_home/manage_home_view.dart index d25f419..47122c0 100644 --- a/lib/features/menu/view/widgets/manage_home/manage_home_view.dart +++ b/lib/features/menu/view/widgets/manage_home/manage_home_view.dart @@ -16,85 +16,74 @@ class ManageHomeView extends StatelessWidget { var spaces = HomeCubit.getInstance().spaces; return DefaultScaffold( title: 'Manage Your Home', - child: spaces == null + height: MediaQuery.sizeOf(context).height, + child: spaces.isEmpty ? const Center( child: BodyMedium(text: 'No spaces found'), ) - : Column( - children: [ - DefaultContainer( - padding: const EdgeInsets.symmetric( - horizontal: 25, - vertical: 20, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.start, - children: List.generate( - spaces.length, - (index) { - if (index == spaces.length - 1) { - return InkWell( - onTap: () { - Navigator.of(context).push(CustomPageRoute( - builder: (context) => HomeSettingsView( - space: spaces[index], - ))); - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - BodyMedium(text: StringHelpers.toTitleCase(spaces[index].name)), - const Icon( - Icons.arrow_forward_ios, - color: ColorsManager.greyColor, - size: 15, - ) - ], - ), - ); - } - return InkWell( - onTap: () { - //TODO refactor the routing to use named routes - // Navigator.of(context).pushNamed( - // '/home_settings', - // arguments: spaces[index], - // ); + : DefaultContainer( + padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25), + child: ListView.builder( + itemCount: spaces.length, + itemBuilder: (context, index) { + if (index == spaces.length - 1) { + return InkWell( + onTap: () { + Navigator.of(context).push(CustomPageRoute( + builder: (context) => HomeSettingsView( + space: spaces[index], + ))); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + BodyMedium(text: StringHelpers.toTitleCase(spaces[index].name)), + const Icon( + Icons.arrow_forward_ios, + color: ColorsManager.greyColor, + size: 15, + ) + ], + ), + ); + } + return InkWell( + onTap: () { + //TODO refactor the routing to use named routes + // Navigator.of(context).pushNamed( + // '/home_settings', + // arguments: spaces[index], + // ); - Navigator.of(context).push(CustomPageRoute( - builder: (context) => HomeSettingsView( - space: spaces[index], - ))); - }, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, + Navigator.of(context).push(CustomPageRoute( + builder: (context) => HomeSettingsView( + space: spaces[index], + ))); + }, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - BodyMedium(text: HomeCubit.getInstance().spaces![index].name), - const Icon( - Icons.arrow_forward_ios, - color: ColorsManager.greyColor, - size: 15, - ) - ], - ), - Container( - margin: const EdgeInsets.symmetric(vertical: 15), - height: 1, + BodyMedium(text: HomeCubit.getInstance().spaces[index].name), + const Icon( + Icons.arrow_forward_ios, color: ColorsManager.greyColor, - ), + size: 15, + ) ], ), - ); - }, - ), - ), - ), - ], + Container( + margin: const EdgeInsets.symmetric(vertical: 15), + height: 1, + color: ColorsManager.greyColor, + ), + ], + ), + ); + }), )); } } From 8393ec353a357907e6d9817b3241d2f579684f24 Mon Sep 17 00:00:00 2001 From: mohammad Date: Thu, 20 Feb 2025 16:02:25 +0300 Subject: [PATCH 8/9] fetchDevices by projectUuid --- .../manage_unit_bloc/manage_unit_bloc.dart | 3 +- .../widgets/manage_home/assign_devices.dart | 3 +- lib/services/api/api_links_endpoints.dart | 2 ++ lib/services/api/home_management_api.dart | 34 ++++++++++++++++--- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart b/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart index 0883eb9..47dd564 100644 --- a/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart +++ b/lib/features/menu/bloc/manage_unit_bloc/manage_unit_bloc.dart @@ -51,7 +51,8 @@ class ManageUnitBloc extends Bloc { spaceUuid: event.unit.id, roomId: event.roomId, projectId: project?.uuid ?? TempConst.projectIdDev); - allDevices = await HomeManagementAPI.fetchDevicesByUserId(); + allDevices = await HomeManagementAPI.fetchDevices( + project?.uuid ?? TempConst.projectIdDev); List allDevicesIds = []; diff --git a/lib/features/menu/view/widgets/manage_home/assign_devices.dart b/lib/features/menu/view/widgets/manage_home/assign_devices.dart index 12421aa..9931d30 100644 --- a/lib/features/menu/view/widgets/manage_home/assign_devices.dart +++ b/lib/features/menu/view/widgets/manage_home/assign_devices.dart @@ -28,8 +28,7 @@ class AssignDeviceView extends StatelessWidget { listener: (context, state) { if (state is FetchDeviceByRoomIdState) { if (state.allDevices.isEmpty) { - CustomSnackBar.displaySnackBar( - 'You do not have the permission to assign devices'); + CustomSnackBar.displaySnackBar('You do not have the devices'); Navigator.of(context).pop(); } } diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index 65dcc18..8710430 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -88,6 +88,8 @@ abstract class ApiEndpoints { //SPACE Module //GET static const String userSpaces = '/user/{userUuid}/spaces'; + static const String devices = '/projects/{projectUuid}/devices'; + static const String spaceDevices = '/projects/{projectUuid}/communities/{communityUuid}/spaces/{spaceUuid}/devices'; diff --git a/lib/services/api/home_management_api.dart b/lib/services/api/home_management_api.dart index 8febf4b..277b2db 100644 --- a/lib/services/api/home_management_api.dart +++ b/lib/services/api/home_management_api.dart @@ -27,7 +27,23 @@ class HomeManagementAPI { return list; } - static Future> fetchDevicesByUnitId(String projectUuid) async { + static Future> fetchDevices(projectUuid) async { + List list = []; + + await _httpService.get( + path: ApiEndpoints.devices.replaceAll("{projectUuid}", projectUuid), + showServerMessage: false, + expectedResponseModel: (json) { + json.forEach((value) { + list.add(DeviceModel.fromJson(value)); + }); + }); + + return list; + } + + static Future> fetchDevicesByUnitId( + String projectUuid) async { List list = []; try { @@ -62,8 +78,12 @@ class HomeManagementAPI { return list; } - static Future> assignDeviceToRoom(String communityId, - String spaceId, String subSpaceId, String deviceId, String projectId) async { + static Future> assignDeviceToRoom( + String communityId, + String spaceId, + String subSpaceId, + String deviceId, + String projectId) async { try { final response = await _httpService.post( path: ApiEndpoints.assignDeviceToRoom @@ -82,8 +102,12 @@ class HomeManagementAPI { } } - static Future> unAssignDeviceToRoom(String communityId, - String spaceId, String subSpaceId, String deviceId, String projectId) async { + static Future> unAssignDeviceToRoom( + String communityId, + String spaceId, + String subSpaceId, + String deviceId, + String projectId) async { try { final response = await _httpService.delete( path: ApiEndpoints.assignDeviceToRoom From 22789234fefbe6fbd63b1500e00fa47c25b4e013 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 23 Feb 2025 16:30:50 +0300 Subject: [PATCH 9/9] Sensitivity Start from 1 --- .../view/widgets/ceiling_sensor/ceiling_sensor_interface.dart | 2 +- pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart b/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart index ce3ee94..1a29914 100644 --- a/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart +++ b/lib/features/devices/view/widgets/ceiling_sensor/ceiling_sensor_interface.dart @@ -332,7 +332,7 @@ class CeilingSensorInterface extends StatelessWidget { title: title.toString(), sensor: ceilingSensor, value: model.sensitivity, - min: 0, + min: 1, max: 10, )); if (result != null) { diff --git a/pubspec.yaml b/pubspec.yaml index b60a986..89f008e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 1.0.27+64 +version: 1.0.30+1 environment: sdk: ">=3.0.6 <4.0.0"