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/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/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/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..9ed0b6c 100644 --- a/lib/utils/constants/temp_const.dart +++ b/lib/utils/constants/temp_const.dart @@ -1,3 +1,5 @@ +import 'package:flutter_dotenv/flutter_dotenv.dart'; + class TempConst { - static const projectId = '0e62577c-06fa-41b9-8a92-99a21fbaf51c'; + static String projectIdDev = dotenv.env['projectId'] ?? ''; }