diff --git a/lib/pages/analytics/modules/occupancy/helpers/fetch_occupancy_data_helper.dart b/lib/pages/analytics/modules/occupancy/helpers/fetch_occupancy_data_helper.dart index 06ae659b..4141a5c3 100644 --- a/lib/pages/analytics/modules/occupancy/helpers/fetch_occupancy_data_helper.dart +++ b/lib/pages/analytics/modules/occupancy/helpers/fetch_occupancy_data_helper.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_bloc.dart'; import 'package:syncrow_web/pages/analytics/modules/energy_management/helpers/fetch_energy_management_data_helper.dart'; import 'package:syncrow_web/pages/analytics/modules/occupancy/blocs/occupancy/occupancy_bloc.dart'; import 'package:syncrow_web/pages/analytics/params/get_occupancy_param.dart'; @@ -21,5 +22,11 @@ abstract final class FetchOccupancyDataHelper { ), ), ); + + context.read() + ..add(const RealtimeDeviceChangesClosed()) + ..add( + const RealtimeDeviceChangesStarted('14fe6e7e-47af-4a07-ae0a-7c4a26ef8135'), + ); } } diff --git a/lib/pages/analytics/modules/occupancy/widgets/occupancy_end_side_bar.dart b/lib/pages/analytics/modules/occupancy/widgets/occupancy_end_side_bar.dart index 8c6e8205..788d087e 100644 --- a/lib/pages/analytics/modules/occupancy/widgets/occupancy_end_side_bar.dart +++ b/lib/pages/analytics/modules/occupancy/widgets/occupancy_end_side_bar.dart @@ -1,6 +1,10 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_web/pages/analytics/models/power_clamp_energy_status.dart'; +import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_bloc.dart'; +import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_data_device_dropdown.dart'; import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_status_widget.dart'; +import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; @@ -12,68 +16,90 @@ class OccupancyEndSideBar extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - decoration: subSectionContainerDecoration.copyWith( - borderRadius: BorderRadius.circular(30), - ), - padding: const EdgeInsetsDirectional.all(32), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - _buildHeader(context), - Text( - 'Device ID:', - style: context.textTheme.bodySmall?.copyWith( - color: ColorsManager.textPrimaryColor, - fontWeight: FontWeight.w400, - fontSize: 12, - ), + return BlocBuilder( + builder: (context, state) { + return Container( + decoration: subSectionContainerDecoration.copyWith( + borderRadius: BorderRadius.circular(30), ), - const SizedBox(height: 6), - SelectableText( - (const Uuid().v4()), - style: context.textTheme.bodySmall?.copyWith( - color: ColorsManager.blackColor, - fontWeight: FontWeight.w400, - fontSize: 12, - ), - ), - const SizedBox(height: 10), - const Divider(height: 1, color: ColorsManager.greyColor), - const SizedBox(height: 50), - SizedBox( - height: MediaQuery.sizeOf(context).height * 0.2, - child: const Expanded( - child: PowerClampEnergyStatusWidget( - status: [ - PowerClampEnergyStatus( - iconPath: Assets.presenceState, - title: 'Presence Status', - value: 'Presence', - unit: '', - ), - PowerClampEnergyStatus( - iconPath: Assets.presenceTimeIcon, - title: 'Presence Time', - value: '15 Mins', - unit: '', - ), - PowerClampEnergyStatus( - iconPath: Assets.currentDistanceIcon, - title: 'Detection Distance', - value: '1.5M', - unit: '', - ), - ], + padding: const EdgeInsetsDirectional.all(32), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildHeader(context), + Text( + 'Device ID:', + style: context.textTheme.bodySmall?.copyWith( + color: ColorsManager.textPrimaryColor, + fontWeight: FontWeight.w400, + fontSize: 12, + ), ), - ), + const SizedBox(height: 6), + SelectableText( + (const Uuid().v4()), + style: context.textTheme.bodySmall?.copyWith( + color: ColorsManager.blackColor, + fontWeight: FontWeight.w400, + fontSize: 12, + ), + ), + const SizedBox(height: 10), + const Divider(height: 1, color: ColorsManager.greyColor), + const SizedBox(height: 50), + SizedBox( + height: MediaQuery.sizeOf(context).height * 0.2, + child: PowerClampEnergyStatusWidget( + status: [ + PowerClampEnergyStatus( + iconPath: Assets.presenceState, + title: 'Presence Status', + value: _valueFromCode( + 'presence_state', + state.deviceStatusList, + ), + unit: '', + ), + PowerClampEnergyStatus( + iconPath: Assets.presenceTimeIcon, + title: 'Presence Time', + value: + '${_valueFromCode('none_body_time', state.deviceStatusList)} Min', + unit: '', + ), + PowerClampEnergyStatus( + iconPath: Assets.currentDistanceIcon, + title: 'Detection Distance', + value: + '${_valueFromCode('space_move_val', state.deviceStatusList)} M', + unit: '', + ), + ], + ), + ), + const SizedBox(height: 20), + ], ), - const SizedBox(height: 20), - ], - ), + ); + }, ); } + String _valueFromCode( + String code, + List status, { + String? defaultValue, + }) { + final value = status + .firstWhere( + (e) => e.code == code, + orElse: () => Status(code: '--', value: '--'), + ) + .value + .toString(); + return value == 'null' ? defaultValue ?? '--' : value; + } + Widget _buildHeader(BuildContext context) { return Row( mainAxisSize: MainAxisSize.min, @@ -98,8 +124,7 @@ class OccupancyEndSideBar extends StatelessWidget { child: FittedBox( fit: BoxFit.scaleDown, alignment: AlignmentDirectional.centerEnd, - // child: PowerClampEnergyDataDeviceDropdown(), - child: Placeholder(fallbackHeight: 30), + child: PowerClampEnergyDataDeviceDropdown(), ), ), ], diff --git a/lib/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart b/lib/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart index 2fd379e4..4080e89b 100644 --- a/lib/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart +++ b/lib/pages/analytics/services/realtime_device_service/firebase_realtime_device_service.dart @@ -23,7 +23,7 @@ class FirebaseRealtimeDeviceService implements RealtimeDeviceService { return Status( code: status['code']?.toString() ?? '', - value: num.tryParse(status['value']?.toString() ?? '0'), + value: status['value']?.toString() ?? '', ); }).toList(); });