diff --git a/assets/icons/frequency_icon.svg b/assets/icons/frequency_icon.svg new file mode 100644 index 00000000..d093af37 --- /dev/null +++ b/assets/icons/frequency_icon.svg @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/icons/power_active_icon.svg b/assets/icons/power_active_icon.svg new file mode 100644 index 00000000..28b1412a --- /dev/null +++ b/assets/icons/power_active_icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/assets/icons/speedo_meter.svg b/assets/icons/speedo_meter.svg new file mode 100644 index 00000000..be3b5c4b --- /dev/null +++ b/assets/icons/speedo_meter.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/assets/icons/volt-meter.svg b/assets/icons/volt-meter.svg new file mode 100644 index 00000000..6691a7dd --- /dev/null +++ b/assets/icons/volt-meter.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/assets/icons/volt_meter_icon.svg b/assets/icons/volt_meter_icon.svg new file mode 100644 index 00000000..97b9037d --- /dev/null +++ b/assets/icons/volt_meter_icon.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart b/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart index d3eb7120..64e3fd50 100644 --- a/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart +++ b/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_event.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_state.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/models/wall_light_status_model.dart'; @@ -9,118 +8,60 @@ import 'package:syncrow_web/services/devices_mang_api.dart'; class SmartPowerBloc extends Bloc { SmartPowerBloc({required this.deviceId}) : super(SmartPowerInitial()) { on(_onFetchDeviceStatus); - on(_onControl); + // on(_onControl); on(_onFetchBatchStatus); on(_onBatchControl); - on(_onFactoryReset); + // on(_onFactoryReset); } - late SmartPowerStatusModel deviceStatus; + late PowerClampModel deviceStatus; final String deviceId; Timer? _timer; - + List> phaseData = []; FutureOr _onFetchDeviceStatus( SmartPowerFetchDeviceEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - // final status = - // await DevicesManagementApi().getDeviceStatus(event.deviceId); - // deviceStatus = - // SmartPowerStatusModel.fromJson(event.deviceId, status.status); + var status = await DevicesManagementApi().getPowerClampInfo(event.deviceId); + deviceStatus = PowerClampModel.fromJson(status); + + phaseData = [ + { + 'name': 'Phase A', + 'voltage': '${deviceStatus.status.phaseA.dataPoints[0].value} V', + 'current': '${deviceStatus.status.phaseA.dataPoints[1].value} A', + 'activePower': '${deviceStatus.status.phaseA.dataPoints[2].value} W', + 'powerFactor': '${deviceStatus.status.phaseA.dataPoints[3].value}', + }, + { + 'name': 'Phase B', + 'voltage': '${deviceStatus.status.phaseB.dataPoints[0].value} V', + 'current': '${deviceStatus.status.phaseB.dataPoints[1].value} A', + 'activePower': '${deviceStatus.status.phaseB.dataPoints[2].value} W', + 'powerFactor': '${deviceStatus.status.phaseB.dataPoints[3].value}', + }, + { + 'name': 'Phase C', + 'voltage': '${deviceStatus.status.phaseC.dataPoints[0].value} V', + 'current': '${deviceStatus.status.phaseC.dataPoints[1].value} A', + 'activePower': '${deviceStatus.status.phaseC.dataPoints[2].value} W', + 'powerFactor': '${deviceStatus.status.phaseC.dataPoints[3].value}', + }, + ]; emit(SmartPowerStatusLoaded(deviceStatus)); } catch (e) { emit(SmartPowerError(e.toString())); } } - FutureOr _onControl( - SmartPowerControl event, Emitter emit) async { - final oldValue = _getValueByCode(event.code); - - _updateLocalValue(event.code, event.value); - - emit(SmartPowerStatusLoaded(deviceStatus)); - - await _runDebounce( - deviceId: event.deviceId, - code: event.code, - value: event.value, - oldValue: oldValue, - emit: emit, - isBatch: false, - ); - } - - Future _runDebounce({ - required dynamic deviceId, - required String code, - required bool value, - required bool oldValue, - required Emitter emit, - required bool isBatch, - }) async { - late String id; - - if (deviceId is List) { - id = deviceId.first; - } else { - id = deviceId; - } - - if (_timer != null) { - _timer!.cancel(); - } - - _timer = Timer(const Duration(milliseconds: 500), () async { - try { - late bool response; - - if (isBatch) { - response = await DevicesManagementApi() - .deviceBatchControl(deviceId, code, value); - } else { - response = await DevicesManagementApi() - .deviceControl(deviceId, Status(code: code, value: value)); - } - - if (!response) { - _revertValueAndEmit(id, code, oldValue, emit); - } - } catch (e) { - _revertValueAndEmit(id, code, oldValue, emit); - } - }); - } - - void _revertValueAndEmit(String deviceId, String code, bool oldValue, - Emitter emit) { - _updateLocalValue(code, oldValue); - emit(SmartPowerStatusLoaded(deviceStatus)); - } - - void _updateLocalValue(String code, bool value) { - if (code == 'switch_1') { - deviceStatus = deviceStatus.copyWith(switch1: value); - } - } - - bool _getValueByCode(String code) { - switch (code) { - case 'switch_1': - return deviceStatus.switch1; - default: - return false; - } - } - Future _onFetchBatchStatus( SmartPowerFetchBatchEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { final status = await DevicesManagementApi().getBatchStatus(event.devicesIds); - deviceStatus = - SmartPowerStatusModel.fromJson(event.devicesIds.first, status.status); + // deviceStatus = + // SmartPowerStatusModel.fromJson(event.devicesIds.first, status.status); emit(SmartPowerStatusLoaded(deviceStatus)); } catch (e) { emit(SmartPowerError(e.toString())); @@ -135,37 +76,30 @@ class SmartPowerBloc extends Bloc { FutureOr _onBatchControl( SmartPowerBatchControl event, Emitter emit) async { - final oldValue = _getValueByCode(event.code); + // final oldValue = _getValueByCode(event.code); - _updateLocalValue(event.code, event.value); + // _updateLocalValue(event.code, event.value); emit(SmartPowerStatusLoaded(deviceStatus)); - await _runDebounce( - deviceId: event.devicesIds, - code: event.code, - value: event.value, - oldValue: oldValue, - emit: emit, - isBatch: true, - ); - } - - FutureOr _onFactoryReset( - WallLightFactoryReset event, Emitter emit) async { - emit(SmartPowerLoading()); - try { - final response = await DevicesManagementApi().factoryReset( - event.factoryReset, - event.deviceId, - ); - if (!response) { - emit(SmartPowerError('Failed')); - } else { - emit(SmartPowerStatusLoaded(deviceStatus)); + FutureOr _onFactoryReset( + WallLightFactoryReset event, Emitter emit) async { + emit(SmartPowerLoading()); + try { + final response = await DevicesManagementApi().factoryReset( + event.factoryReset, + event.deviceId, + ); + if (!response) { + emit(SmartPowerError('Failed')); + } else { + emit(SmartPowerStatusLoaded(deviceStatus)); + } + } catch (e) { + emit(SmartPowerError(e.toString())); } - } catch (e) { - emit(SmartPowerError(e.toString())); } } + + } diff --git a/lib/pages/device_managment/power_clamp/bloc/smart_power_event.dart b/lib/pages/device_managment/power_clamp/bloc/smart_power_event.dart index 15a034fc..9eb680cd 100644 --- a/lib/pages/device_managment/power_clamp/bloc/smart_power_event.dart +++ b/lib/pages/device_managment/power_clamp/bloc/smart_power_event.dart @@ -57,3 +57,12 @@ class WallLightFactoryReset extends SmartPowerEvent { @override List get props => [deviceId, factoryReset]; } +class PageChangedEvent extends SmartPowerEvent { + final int newPage; + PageChangedEvent(this.newPage); +} + +class PageArrowPressedEvent extends SmartPowerEvent { + final int direction; + PageArrowPressedEvent(this.direction); +} \ No newline at end of file diff --git a/lib/pages/device_managment/power_clamp/bloc/smart_power_state.dart b/lib/pages/device_managment/power_clamp/bloc/smart_power_state.dart index 005f5c70..9b60a8d3 100644 --- a/lib/pages/device_managment/power_clamp/bloc/smart_power_state.dart +++ b/lib/pages/device_managment/power_clamp/bloc/smart_power_state.dart @@ -11,7 +11,7 @@ class SmartPowerInitial extends SmartPowerState {} class SmartPowerLoading extends SmartPowerState {} class SmartPowerStatusLoaded extends SmartPowerState { - final SmartPowerStatusModel status; + final PowerClampModel status; SmartPowerStatusLoaded(this.status); @@ -54,3 +54,4 @@ class SmartPowerBatchStatusLoaded extends SmartPowerState { @override List get props => [status]; } + diff --git a/lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart b/lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart index 15060492..7fb09d47 100644 --- a/lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart +++ b/lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart @@ -1,47 +1,86 @@ -import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; +// PowerClampModel class to represent the response +class PowerClampModel { + String productUuid; + String productType; + PowerStatus status; -class SmartPowerStatusModel { - final String uuid; - final bool switch1; - final int countDown; - - SmartPowerStatusModel({ - required this.uuid, - required this.switch1, - required this.countDown, + PowerClampModel({ + required this.productUuid, + required this.productType, + required this.status, }); - factory SmartPowerStatusModel.fromJson(String id, List jsonList) { - late bool switch1; - late int countDown; - - for (var status in jsonList) { - switch (status.code) { - case 'switch_1': - switch1 = status.value ?? false; - break; - case 'countdown_1': - countDown = status.value ?? 0; - break; - } - } - - return SmartPowerStatusModel( - uuid: id, - switch1: switch1, - countDown: countDown, - ); - } - - SmartPowerStatusModel copyWith({ - String? uuid, - bool? switch1, - int? countDown, - }) { - return SmartPowerStatusModel( - uuid: uuid ?? this.uuid, - switch1: switch1 ?? this.switch1, - countDown: countDown ?? this.countDown, + factory PowerClampModel.fromJson(Map json) { + return PowerClampModel( + productUuid: json['productUuid'], + productType: json['productType'], + status: PowerStatus.fromJson(json['status']), + ); + } +} + +class PowerStatus { + Phase phaseA; + Phase phaseB; + Phase phaseC; + Phase general; + + PowerStatus({ + required this.phaseA, + required this.phaseB, + required this.phaseC, + required this.general, + }); + + factory PowerStatus.fromJson(Map json) { + return PowerStatus( + phaseA: Phase.fromJson(json['phaseA']), + phaseB: Phase.fromJson(json['phaseB']), + phaseC: Phase.fromJson(json['phaseC']), + general: Phase.fromJson(json['general'] + // List.from( + // json['general'].map((x) => DataPoint.fromJson(x))), + )); + } +} + +class Phase { + List dataPoints; + + Phase({required this.dataPoints}); + + factory Phase.fromJson(List json) { + return Phase( + dataPoints: json.map((x) => DataPoint.fromJson(x)).toList(), + ); + } +} + +class DataPoint { + dynamic code; + dynamic customName; + dynamic dpId; + dynamic time; + dynamic type; + dynamic value; + + DataPoint({ + required this.code, + required this.customName, + required this.dpId, + required this.time, + required this.type, + required this.value, + }); + + factory DataPoint.fromJson(Map json) { + return DataPoint( + code: json['code'], + customName: json['customName'], + dpId: json['dpId'], + time: json['time'], + type: json['type'], + value: json['value'], ); } } diff --git a/lib/pages/device_managment/power_clamp/view/phase_widget.dart b/lib/pages/device_managment/power_clamp/view/phase_widget.dart new file mode 100644 index 00000000..223acd95 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/view/phase_widget.dart @@ -0,0 +1,124 @@ +import 'package:flutter/material.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_info_card.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; + +class PhaseWidget extends StatefulWidget { + final List> phaseData; + + PhaseWidget({ + required this.phaseData, + }); + @override + _PhaseWidgetState createState() => _PhaseWidgetState(); +} + +class _PhaseWidgetState extends State { + int _selectedPhaseIndex = 0; + + @override + Widget build(BuildContext context) { + return Column( + children: [ + SizedBox(height: 10), + Row( + children: List.generate(widget.phaseData.length, (index) { + return InkWell( + onTap: () { + setState(() { + _selectedPhaseIndex = index; + }); + }, + child: Padding( + padding: const EdgeInsets.only(left: 10, right: 10), + child: Text( + widget.phaseData[index]['name'], + style: TextStyle( + fontWeight: FontWeight.bold, + color: _selectedPhaseIndex == index + ? Colors.black + : Colors.grey, + ), + ), + ), + ); + }), + ), + SizedBox(height: 10), + _selectedPhaseIndex == 0 + ? phase( + totalActive: widget.phaseData[0]['activePower'] ?? '0', + totalCurrent: widget.phaseData[0]['current'] ?? '0', + totalFactor: widget.phaseData[0]['powerFactor'] ?? '0', + totalVoltage: widget.phaseData[0]['voltage'] ?? '0', + ) + : _selectedPhaseIndex == 1 + ? phase( + totalActive: widget.phaseData[1]['activePower'] ?? '0', + totalCurrent: widget.phaseData[1]['current'] ?? '0', + totalFactor: widget.phaseData[1]['powerFactor'] ?? '0', + totalVoltage: widget.phaseData[1]['voltage'] ?? '0', + ) + : phase( + totalActive: widget.phaseData[2]['activePower'] ?? '0', + totalCurrent: widget.phaseData[2]['current'] ?? '0', + totalFactor: widget.phaseData[2]['powerFactor'] ?? '0', + totalVoltage: widget.phaseData[2]['voltage'] ?? '0', + ), + ], + ); + } +} + +class phase extends StatelessWidget { + const phase({ + super.key, + required this.totalVoltage, + required this.totalCurrent, + required this.totalActive, + required this.totalFactor, + }); + + final String totalVoltage; + final String totalCurrent; + final String totalActive; + final String totalFactor; + + @override + Widget build(BuildContext context) { + return Container( + child: Column( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + PowerClampInfoCard( + iconPath: Assets.voltageIcon, + title: 'Voltage', + value: totalVoltage, + unit: '', + ), + PowerClampInfoCard( + iconPath: Assets.voltMeterIcon, + title: 'Current', + value: totalCurrent, + unit: '', + ), + PowerClampInfoCard( + iconPath: Assets.powerActiveIcon, + title: 'Active Power', + value: totalActive, + unit: '', + ), + PowerClampInfoCard( + iconPath: Assets.speedoMeter, + title: 'Power Factor', + value: totalFactor, + unit: '', + ), + ], + ), + ], + ), + ); + } +} diff --git a/lib/pages/device_managment/power_clamp/view/power_chart.dart b/lib/pages/device_managment/power_clamp/view/power_chart.dart index 2cd4ce5b..28e91cd5 100644 --- a/lib/pages/device_managment/power_clamp/view/power_chart.dart +++ b/lib/pages/device_managment/power_clamp/view/power_chart.dart @@ -28,9 +28,62 @@ class _EnergyConsumptionPageState extends State { @override Widget build(BuildContext context) { - return Scaffold( - body: Column( + return Container( + color: ColorsManager.whiteColors, + child: Column( children: [ + const Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Total Consumption', + style: TextStyle( + fontWeight: FontWeight.w700, + fontSize: 20, + ), + ), + Text( + '8623.20 kWh', + style: TextStyle( + fontWeight: FontWeight.w700, + fontSize: 20, + ), + ), + ], + ), + const Row( + children: [ + Text( + 'Energy consumption', + style: TextStyle( + color: ColorsManager.grayColor, + fontWeight: FontWeight.w700, + fontSize: 12, + ), + ), + ], + ), + const Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + '01/08/2024 - 31/08/2024', + style: TextStyle( + color: ColorsManager.grayColor, + fontWeight: FontWeight.w400, + fontSize: 8, + ), + ), + Text( + '1000.00 kWh', + style: TextStyle( + color: ColorsManager.grayColor, + fontWeight: FontWeight.w400, + fontSize: 8, + ), + ), + ], + ), Expanded( child: Padding( padding: const EdgeInsets.only(top: 15), @@ -78,7 +131,7 @@ class _EnergyConsumptionPageState extends State { ), topTitles: AxisTitles( sideTitles: SideTitles( - showTitles: true, + showTitles: false, reservedSize: 70, getTitlesWidget: (value, meta) { int index = value.toInt(); diff --git a/lib/pages/device_managment/power_clamp/view/power_info_card.dart b/lib/pages/device_managment/power_clamp/view/power_info_card.dart index de90da4f..b4dd487a 100644 --- a/lib/pages/device_managment/power_clamp/view/power_info_card.dart +++ b/lib/pages/device_managment/power_clamp/view/power_info_card.dart @@ -24,56 +24,50 @@ class PowerClampInfoCard extends StatelessWidget { padding: const EdgeInsets.all(5.0), child: Container( decoration: BoxDecoration( - color: Colors.white, + color: ColorsManager.graysColor, borderRadius: BorderRadius.circular(20), ), height: 55, - color: ColorsManager.graysColor, child: Row( crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ - Expanded( - child: SvgPicture.asset( - iconPath, - fit: BoxFit.fill, - ), + SvgPicture.asset( + iconPath, + fit: BoxFit.fill, ), - Expanded( - flex: 3, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - value, - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w700, + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + title, + style: TextStyle( + fontSize: 8, + fontWeight: FontWeight.w400, + ), + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + value, + style: TextStyle( + fontSize: 15, + fontWeight: FontWeight.w700, + ), ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - value, - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w700, - ), + Text( + unit, + style: TextStyle( + fontSize: 15, + fontWeight: FontWeight.w700, ), - Text( - unit, - style: TextStyle( - fontSize: 15, - fontWeight: FontWeight.w700, - ), - ), - ], - ), - ], - ), + ), + ], + ), + ], ) ], ), diff --git a/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart b/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart index 2e6ee338..6945fde6 100644 --- a/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart +++ b/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart @@ -1,66 +1,234 @@ import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_event.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_state.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_chart.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_info_card.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/phase_widget.dart'; +import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; //Smart Power Clamp -class SmartPowerDeviceControl extends StatelessWidget +class SmartPowerDeviceControl extends StatefulWidget with HelperResponsiveLayout { final String deviceId; const SmartPowerDeviceControl({super.key, required this.deviceId}); + + @override + State createState() => + _SmartPowerDeviceControlState(); +} + +class _SmartPowerDeviceControlState extends State { @override Widget build(BuildContext context) { - return _buildStatusControls( - context, + return BlocProvider( + create: (context) => SmartPowerBloc(deviceId: widget.deviceId) + ..add(SmartPowerFetchDeviceEvent(widget.deviceId)), + child: BlocBuilder( + builder: (context, state) { + final _blocProvider = BlocProvider.of(context); + + if (state is SmartPowerLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is SmartPowerStatusLoaded) { + return _buildStatusControls( + context: context, + blocProvider: _blocProvider, + ); + } + return const Center(child: CircularProgressIndicator()); + // } + }, + ), ); - - // BlocProvider( - // create: (context) => SmartPowerBloc(deviceId: deviceId) - // ..add(SmartPowerFetchDeviceEvent(deviceId)), - // child: BlocBuilder( - // builder: (context, state) { - // if (state is SmartPowerLoading) { - // return const Center(child: CircularProgressIndicator()); - // } else if (state is SmartPowerStatusLoaded) { - // return _buildStatusControls(context, state.status); - // } - - // // else if (state is WallLightSwitchError || - // // state is WallLightSwitchControlError) { - // // return const Center(child: Text('Error fetching status')); - // // } else { - // return const Center(child: CircularProgressIndicator()); - // // } - // }, - // ), - // ); } - Widget _buildStatusControls( - BuildContext context, - ) { - final isExtraLarge = isExtraLargeScreenSize(context); - final isLarge = isLargeScreenSize(context); - final isMedium = isMediumScreenSize(context); + Widget _buildStatusControls({ + required BuildContext context, + required SmartPowerBloc blocProvider, + }) { + PageController _pageController = PageController(); + int _currentPage = 0; + + void _onArrowPressed(int direction) { + setState(() { + _currentPage = (_currentPage + direction) % 3; + if (_currentPage < 0) { + _currentPage = 2; + } + _pageController.animateToPage( + _currentPage, + duration: Duration(milliseconds: 300), + curve: Curves.easeInOut, + ); + }); + } + return Container( - height: 150, - child: EnergyConsumptionPage( - chartData: [ - EnergyData('12:00 AM', 4.0), - EnergyData('01:00 AM', 3.5), - EnergyData('02:00 AM', 3.8), - EnergyData('03:00 AM', 3.2), - EnergyData('04:00 AM', 4.0), - EnergyData('05:00 AM', 3.4), - EnergyData('06:00 AM', 3.2), - EnergyData('07:00 AM', 3.5), - EnergyData('08:00 AM', 3.8), - EnergyData('09:00 AM', 3.6), - EnergyData('10:00 AM', 3.9), - EnergyData('11:00 AM', 4.0), - ], - totalConsumption: 10000, - date: '10/08/2024', + child: DeviceControlsContainer( + child: Column( + children: [ + const Row( + children: [ + Text( + 'Live', + style: TextStyle( + fontSize: 32, + fontWeight: FontWeight.w700, + color: ColorsManager.grayColor), + ), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + PowerClampInfoCard( + iconPath: Assets.powerActiveIcon, + title: 'Active', + value: blocProvider + .deviceStatus.status.general.dataPoints[0].value + .toString(), + unit: '', + ), + PowerClampInfoCard( + iconPath: Assets.voltMeterIcon, + title: 'Current', + value: blocProvider + .deviceStatus.status.general.dataPoints[1].value + .toString(), + unit: ' A', + ), + PowerClampInfoCard( + iconPath: Assets.frequencyIcon, + title: 'Frequency', + value: blocProvider + .deviceStatus.status.general.dataPoints[2].value + .toString(), + unit: ' Hz', + ), + ], + ), + PhaseWidget( + phaseData: blocProvider.phaseData, + ), + Container( + padding: EdgeInsets.all(10), + decoration: BoxDecoration( + color: ColorsManager.whiteColors, + borderRadius: BorderRadius.circular(20), + ), + height: 250, + child: Column( + children: [ + Container( + decoration: BoxDecoration( + color: ColorsManager.graysColor, + borderRadius: BorderRadius.circular(20), + ), + height: 60, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + IconButton( + icon: Icon(Icons.arrow_left), + onPressed: () => _onArrowPressed(-1), + ), + Text( + _currentPage == 0 + ? 'Total' + : _currentPage == 0 + ? 'Phase A' + : _currentPage == 0 + ? 'Phase B' + : 'Phase C', + style: TextStyle(fontSize: 18), + ), + IconButton( + icon: Icon(Icons.arrow_right), + onPressed: () => _onArrowPressed(1), + ), + ], + ), + ), + Expanded( + child: PageView( + controller: _pageController, + onPageChanged: (int page) { + setState(() { + _currentPage = page; + }); + }, + children: [ + EnergyConsumptionPage( + chartData: [ + EnergyData('12:00 AM', 4.0), + EnergyData('01:00 AM', 3.5), + EnergyData('02:00 AM', 3.8), + EnergyData('03:00 AM', 3.2), + EnergyData('04:00 AM', 4.0), + EnergyData('05:00 AM', 3.4), + EnergyData('06:00 AM', 3.2), + EnergyData('07:00 AM', 3.5), + EnergyData('08:00 AM', 3.8), + EnergyData('09:00 AM', 3.6), + EnergyData('10:00 AM', 3.9), + EnergyData('10:00 AM', 3.9), + EnergyData('11:00 AM', 4.0), + ], + totalConsumption: 10000, + date: '10/08/2024', + ), + EnergyConsumptionPage( + chartData: [ + EnergyData('12:00 AM', 4.0), + EnergyData('01:00 AM', 3.5), + EnergyData('02:00 AM', 3.8), + EnergyData('03:00 AM', 3.2), + EnergyData('04:00 AM', 4.0), + EnergyData('05:00 AM', 3.4), + EnergyData('06:00 AM', 3.2), + EnergyData('07:00 AM', 3.5), + EnergyData('08:00 AM', 3.8), + EnergyData('09:00 AM', 3.6), + EnergyData('10:00 AM', 3.9), + EnergyData('10:00 AM', 3.9), + EnergyData('11:00 AM', 4.0), + ], + totalConsumption: 10000, + date: '10/08/2024', + ), + EnergyConsumptionPage( + chartData: [ + EnergyData('12:00 AM', 4.0), + EnergyData('01:00 AM', 6.5), + EnergyData('02:00 AM', 3.8), + EnergyData('03:00 AM', 3.2), + EnergyData('04:00 AM', 6.0), + EnergyData('05:00 AM', 3.4), + EnergyData('06:00 AM', 5.2), + EnergyData('07:00 AM', 3.5), + EnergyData('08:00 AM', 3.8), + EnergyData('09:00 AM', 5.6), + EnergyData('10:00 AM', 6.9), + EnergyData('10:00 AM', 3.9), + EnergyData('11:00 AM', 6.0), + ], + totalConsumption: 10000, + date: '10/08/2024', + ), + ], + ), + ), + ], + ), + ), + ], + ), ), ); } diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index bb591b0d..4abb606f 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -50,6 +50,22 @@ class DevicesManagementApi { } } + Future getPowerClampInfo(String deviceId) async { + try { + final response = await HTTPService().get( + path: ApiEndpoints.powerClamp.replaceAll('{powerClampUuid}', deviceId), + showServerMessage: true, + expectedResponseModel: (json) { + return json; + }, + ); + return response; + } catch (e) { + debugPrint('Error fetching $e'); + return {}; + } + } + //deviceControl Future deviceControl(String uuid, Status status) async { try { @@ -68,7 +84,8 @@ class DevicesManagementApi { } } - Future deviceBatchControl(List uuids, String code, dynamic value) async { + Future deviceBatchControl( + List uuids, String code, dynamic value) async { try { final body = { 'devicesUuid': uuids, @@ -92,7 +109,8 @@ class DevicesManagementApi { } } - static Future> getDevicesByGatewayId(String gatewayId) async { + static Future> getDevicesByGatewayId( + String gatewayId) async { final response = await HTTPService().get( path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId), showServerMessage: false, @@ -126,7 +144,9 @@ class DevicesManagementApi { String code, ) async { final response = await HTTPService().get( - path: ApiEndpoints.getDeviceLogs.replaceAll('{uuid}', uuid).replaceAll('{code}', code), + path: ApiEndpoints.getDeviceLogs + .replaceAll('{uuid}', uuid) + .replaceAll('{code}', code), showServerMessage: false, expectedResponseModel: (json) { return DeviceReport.fromJson(json); @@ -135,7 +155,8 @@ class DevicesManagementApi { return response; } - static Future getDeviceReportsByDate(String uuid, String code, [String? from, String? to]) async { + static Future getDeviceReportsByDate(String uuid, String code, + [String? from, String? to]) async { final response = await HTTPService().get( path: ApiEndpoints.getDeviceLogsByDate .replaceAll('{uuid}', uuid) @@ -174,7 +195,8 @@ class DevicesManagementApi { } } - Future addScheduleRecord(ScheduleEntry sendSchedule, String uuid) async { + Future addScheduleRecord( + ScheduleEntry sendSchedule, String uuid) async { try { final response = await HTTPService().post( path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid), @@ -191,10 +213,13 @@ class DevicesManagementApi { } } - Future> getDeviceSchedules(String uuid, String category) async { + Future> getDeviceSchedules( + String uuid, String category) async { try { final response = await HTTPService().get( - path: ApiEndpoints.getScheduleByDeviceId.replaceAll('{deviceUuid}', uuid).replaceAll('{category}', category), + path: ApiEndpoints.getScheduleByDeviceId + .replaceAll('{deviceUuid}', uuid) + .replaceAll('{category}', category), showServerMessage: true, expectedResponseModel: (json) { List schedules = []; @@ -211,7 +236,10 @@ class DevicesManagementApi { } } - Future updateScheduleRecord({required bool enable, required String uuid, required String scheduleId}) async { + Future updateScheduleRecord( + {required bool enable, + required String uuid, + required String scheduleId}) async { try { final response = await HTTPService().put( path: ApiEndpoints.updateScheduleByDeviceId @@ -232,7 +260,8 @@ class DevicesManagementApi { } } - Future editScheduleRecord(String uuid, ScheduleEntry newSchedule) async { + Future editScheduleRecord( + String uuid, ScheduleEntry newSchedule) async { try { final response = await HTTPService().put( path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid), diff --git a/lib/utils/constants/api_const.dart b/lib/utils/constants/api_const.dart index 23bc5c6c..bf167ab5 100644 --- a/lib/utils/constants/api_const.dart +++ b/lib/utils/constants/api_const.dart @@ -47,5 +47,7 @@ abstract class ApiEndpoints { static const String updateScheduleByDeviceId = '/schedule/enable/{deviceUuid}'; - static const String factoryReset = '/device/factory/reset/{deviceUuid}'; + static const String factoryReset = '/device/factory/reset/{deviceUuid}'; + static const String powerClamp = + '/device/{powerClampUuid}/power-clamp/status'; } diff --git a/lib/utils/constants/assets.dart b/lib/utils/constants/assets.dart index 4ac64bb6..7af0d56c 100644 --- a/lib/utils/constants/assets.dart +++ b/lib/utils/constants/assets.dart @@ -168,4 +168,13 @@ class Assets { //assets/icons/2gang.svg static const String twoGang = 'assets/icons/2gang.svg'; + + + + static const String frequencyIcon = "assets/icons/frequency_icon.svg"; + static const String voltMeterIcon = "assets/icons/volt_meter_icon.svg"; + static const String powerActiveIcon = "assets/icons/power_active_icon.svg"; + static const String searchIcon = "assets/icons/search_icon.svg"; + static const String voltageIcon = "assets/icons/voltage_icon.svg"; + static const String speedoMeter = "assets/icons/speedo_meter.svg"; }