diff --git a/assets/icons/voltage_icon.svg b/assets/icons/voltage_icon.svg new file mode 100644 index 00000000..29b06678 --- /dev/null +++ b/assets/icons/voltage_icon.svg @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 6d4033fa..842dbc97 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 @@ -23,7 +23,6 @@ class SmartPowerBloc extends Bloc { on(_filterRecordsByDate); on(checkDayMonthYearSelected); on(_onFactoryReset); - // FetchPowerClampBatchStatusEvent } late PowerClampModel deviceStatus; @@ -223,27 +222,27 @@ class SmartPowerBloc extends Bloc { phaseData = [ { 'name': 'Phase A', - 'voltage': '${deviceStatus.status.phaseA.dataPoints[0].value} V', - 'current': '${deviceStatus.status.phaseA.dataPoints[1].value} A', + 'voltage': '${deviceStatus.status.phaseA.dataPoints[0].value / 10} V', + 'current': '${deviceStatus.status.phaseA.dataPoints[1].value / 10} 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', + 'voltage': '${deviceStatus.status.phaseB.dataPoints[0].value / 10} V', + 'current': '${deviceStatus.status.phaseB.dataPoints[1].value / 10} 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', + 'voltage': '${deviceStatus.status.phaseC.dataPoints[0].value / 10} V', + 'current': '${deviceStatus.status.phaseC.dataPoints[1].value / 10} A', 'activePower': '${deviceStatus.status.phaseC.dataPoints[2].value} W', 'powerFactor': '${deviceStatus.status.phaseC.dataPoints[3].value}', }, ]; - emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + emit(GetDeviceStatus()); } catch (e) { emit(SmartPowerError(e.toString())); } @@ -253,12 +252,14 @@ class SmartPowerBloc extends Bloc { SmartPowerArrowPressedEvent event, Emitter emit) { currentPage = (currentPage + event.direction + 4) % 4; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + emit(GetDeviceStatus()); } FutureOr _onPageChanged( SmartPowerPageChangedEvent event, Emitter emit) { currentPage = event.page; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + emit(GetDeviceStatus()); } Future _onFactoryReset( @@ -588,14 +589,16 @@ class SmartPowerBloc extends Bloc { TextButton( child: const Text('Cancel'), onPressed: () { - Navigator.of(context).pop(); // Pops without value, returning null + Navigator.of(context) + .pop(); // Pops without value, returning null }, ), TextButton( child: const Text('OK'), onPressed: () { final selectedDateTime = DateTime(selectedYear); - Navigator.of(context).pop(selectedDateTime); // Pops with the selected date + Navigator.of(context).pop( + selectedDateTime); // Pops with the selected date }, ), ], @@ -635,8 +638,7 @@ class SmartPowerBloc extends Bloc { minimumYear: 1900, maximumYear: DateTime.now().year, onDateTimeChanged: (DateTime newDateTime) { - selectedDate = - newDateTime; // Update the selected date when changed + selectedDate = newDateTime; }, ), ), @@ -650,15 +652,13 @@ class SmartPowerBloc extends Bloc { TextButton( child: const Text('Cancel'), onPressed: () { - Navigator.of(context) - .pop(); // Dismiss the modal without returning a value + Navigator.of(context).pop(); }, ), TextButton( child: const Text('OK'), onPressed: () { - Navigator.of(context) - .pop(selectedDate); // Return the selected date + Navigator.of(context).pop(selectedDate); }, ), ], @@ -674,6 +674,7 @@ class SmartPowerBloc extends Bloc { } DateTime? dateTime = DateTime.now(); + String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now()); void checkDayMonthYearSelected( @@ -708,12 +709,17 @@ class SmartPowerBloc extends Bloc { emit(SmartPowerLoading()); }); // Use the selected picker - await dateSelector(event.context).then((newDate) { - add(FilterRecordsByDateEvent( - selectedDate: dateTime!, - viewType: views[currentIndex], - )); + if (newDate.toString() == 'null') { + emit(GetDeviceStatus()); + } else { + dateTime = newDate; + add(FilterRecordsByDateEvent( + selectedDate: newDate!, + viewType: views[currentIndex], + )); + } + // formattedDate = newDate.toString(); }); emit(FilterRecordsState(filteredRecords: energyDataList)); @@ -725,21 +731,24 @@ class SmartPowerBloc extends Bloc { FilterRecordsByDateEvent event, Emitter emit) { emit(SmartPowerLoading()); - print('FilterRecordsByDate method called'); - print('Selected date: ${event.selectedDate}'); - print('View type: ${event.viewType}'); - if (event.viewType == 'Year') { + formattedDate = event.selectedDate.year.toString(); filteredRecords = record .where((record) => record.eventTime!.year == event.selectedDate.year) .toList(); } else if (event.viewType == 'Month') { + formattedDate = + "${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}"; + filteredRecords = record .where((record) => record.eventTime!.year == event.selectedDate.year && record.eventTime!.month == event.selectedDate.month) .toList(); } else if (event.viewType == 'Day') { + formattedDate = + "${event.selectedDate.year.toString()}-${getMonthShortName(event.selectedDate.month)}-${event.selectedDate.day}"; + filteredRecords = record .where((record) => record.eventTime!.year == event.selectedDate.year && @@ -748,9 +757,7 @@ class SmartPowerBloc extends Bloc { .toList(); } - print('Filtered Records: ${filteredRecords.length} items found.'); - - // Update `energyDataList` with filtered records. + selectDateRange(); energyDataList = filteredRecords.map((eventDevice) { return EnergyData( event.viewType == 'Year' @@ -762,14 +769,6 @@ class SmartPowerBloc extends Bloc { double.parse(eventDevice.value!), ); }).toList(); - - // if (filteredRecords.isEmpty) { - // print('No records found for the selected date'); - // } else { - // print('Filtered energyDataList: ${energyDataList.length} items found.'); - // } - - // Emitting state for filtered data emit(FilterRecordsState(filteredRecords: energyDataList)); } @@ -777,4 +776,13 @@ class SmartPowerBloc extends Bloc { final date = DateTime(0, month); return DateFormat.MMM().format(date); } + + String endChartDate = ''; + void selectDateRange() async { + DateTime startDate = dateTime!; + DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1) + .subtract(Duration(days: 1)); + String formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate); + endChartDate = ' - $formattedEndDate'; + } } 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 17e79b7e..62af9e78 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,6 +11,8 @@ class SmartPowerState extends Equatable { class SmartPowerInitial extends SmartPowerState {} class SmartPowerLoading extends SmartPowerState {} +class GetDeviceStatus extends SmartPowerState {} +//GetDeviceStatus class SmartPowerLoadBatchControll extends SmartPowerState { final PowerClampBatchModel status; 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 ce7d6add..dc632478 100644 --- a/lib/pages/device_managment/power_clamp/view/power_chart.dart +++ b/lib/pages/device_managment/power_clamp/view/power_chart.dart @@ -90,188 +90,179 @@ class _EnergyConsumptionPageState extends State { ), ], ), - Expanded( - child: Column( - children: [ - Expanded( - child: Padding( - padding: const EdgeInsets.only(top: 15), - child: LineChart( - LineChartData( - lineTouchData: LineTouchData( - handleBuiltInTouches: true, - touchSpotThreshold: 2, - getTouchLineEnd: (barData, spotIndex) { - return 10.0; + Column( + children: [ + Padding( + padding: const EdgeInsets.only(top: 15), + child: SizedBox( + height: MediaQuery.of(context).size.height * 0.15, + child: LineChart( + LineChartData( + lineTouchData: LineTouchData( + handleBuiltInTouches: true, + touchSpotThreshold: 2, + getTouchLineEnd: (barData, spotIndex) { + return 10.0; + }, + touchTooltipData: LineTouchTooltipData( + getTooltipColor: (touchTooltipItem) => Colors.white, + tooltipRoundedRadius: 10.0, + tooltipPadding: const EdgeInsets.all(8.0), + tooltipBorder: const BorderSide( + color: ColorsManager.grayColor, width: 1), + getTooltipItems: (List touchedSpots) { + return touchedSpots.map((spot) { + return LineTooltipItem( + '${spot.x},\n ${spot.y.toStringAsFixed(2)} kWh', + const TextStyle( + color: Colors.blue, + fontWeight: FontWeight.bold, + fontSize: 12, + ), + ); + }).toList(); }, - touchTooltipData: LineTouchTooltipData( - getTooltipColor: (touchTooltipItem) => - Colors.white, - tooltipRoundedRadius: 10.0, - tooltipPadding: const EdgeInsets.all(8.0), - tooltipBorder: - BorderSide(color: Colors.grey, width: 1), - getTooltipItems: - (List touchedSpots) { - return touchedSpots.map((spot) { - return LineTooltipItem( - '${spot.x},\n ${spot.y.toStringAsFixed(2)} kWh', - const TextStyle( - color: Colors.blue, - fontWeight: FontWeight.bold, - fontSize: 12, - ), - ); - }).toList(); - }, - )), - titlesData: FlTitlesData( - bottomTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: false, - ), - ), - leftTitles: const AxisTitles( - sideTitles: SideTitles( - showTitles: false, - ), - ), - rightTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: false, - ), - ), - topTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: false, - reservedSize: 70, - getTitlesWidget: (value, meta) { - int index = value.toInt(); - if (index >= 0 && index < _chartData.length) { - return Padding( - padding: const EdgeInsets.all(8.0), - child: RotatedBox( - quarterTurns: -1, - child: Text(_chartData[index].time, - style: TextStyle(fontSize: 10)), - ), - ); - } - return const SizedBox.shrink(); - }, - ), + )), + titlesData: FlTitlesData( + bottomTitles: const AxisTitles( + sideTitles: SideTitles( + showTitles: false, ), ), - gridData: FlGridData( + leftTitles: const AxisTitles( + sideTitles: SideTitles( + showTitles: false, + ), + ), + rightTitles: const AxisTitles( + sideTitles: SideTitles( + showTitles: false, + ), + ), + topTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: false, + reservedSize: 70, + getTitlesWidget: (value, meta) { + int index = value.toInt(); + if (index >= 0 && index < _chartData.length) { + return Padding( + padding: const EdgeInsets.all(8.0), + child: RotatedBox( + quarterTurns: -1, + child: Text(_chartData[index].time, + style: TextStyle(fontSize: 10)), + ), + ); + } + return const SizedBox.shrink(); + }, + ), + ), + ), + gridData: FlGridData( + show: true, + drawVerticalLine: true, + horizontalInterval: 1, + verticalInterval: 1, + getDrawingVerticalLine: (value) { + return FlLine( + color: Colors.grey.withOpacity(0.2), + dashArray: [8, 8], + strokeWidth: 1, + ); + }, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.withOpacity(0.2), + dashArray: [5, 5], + strokeWidth: 1, + ); + }, + drawHorizontalLine: false, + ), + lineBarsData: [ + LineChartBarData( + preventCurveOvershootingThreshold: 0.1, + curveSmoothness: 0.5, + preventCurveOverShooting: true, + aboveBarData: BarAreaData(), + spots: _chartData + .asMap() + .entries + .map((entry) => FlSpot(entry.key.toDouble(), + entry.value.consumption)) + .toList(), + isCurved: true, + color: ColorsManager.primaryColor.withOpacity(0.6), show: true, - drawVerticalLine: true, - horizontalInterval: 1, - verticalInterval: 1, - getDrawingVerticalLine: (value) { - return FlLine( - color: Colors.grey.withOpacity(0.2), - dashArray: [8, 8], - strokeWidth: 1, - ); - }, - getDrawingHorizontalLine: (value) { - return FlLine( - color: Colors.grey.withOpacity(0.2), - dashArray: [5, 5], - strokeWidth: 1, - ); - }, - drawHorizontalLine: false, - ), - lineBarsData: [ - LineChartBarData( - preventCurveOvershootingThreshold: 0.1, - curveSmoothness: 0.5, - preventCurveOverShooting: true, - aboveBarData: BarAreaData(), - spots: _chartData - .asMap() - .entries - .map((entry) => FlSpot(entry.key.toDouble(), - entry.value.consumption)) - .toList(), - isCurved: true, - color: ColorsManager.primaryColor.withOpacity(0.6), + shadow: const Shadow(color: Colors.black12), + belowBarData: BarAreaData( show: true, - shadow: Shadow(color: Colors.black12), - belowBarData: BarAreaData( - show: true, - gradient: LinearGradient( - colors: [ - ColorsManager.primaryColor.withOpacity(0.5), - Colors.blue.withOpacity(0.1), - ], - begin: Alignment.center, - end: Alignment.bottomCenter, - ), + gradient: LinearGradient( + colors: [ + ColorsManager.primaryColor.withOpacity(0.5), + Colors.blue.withOpacity(0.1), + ], + begin: Alignment.center, + end: Alignment.bottomCenter, ), - dotData: FlDotData( - show: false, - ), - isStrokeCapRound: true, - barWidth: 2, ), - ], - borderData: FlBorderData( - show: false, - border: Border.all( - color: Color(0xff023DFE).withOpacity(0.7), - width: 10, + dotData: const FlDotData( + show: false, ), + isStrokeCapRound: true, + barWidth: 2, + ), + ], + borderData: FlBorderData( + show: false, + border: Border.all( + color: Color(0xff023DFE).withOpacity(0.7), + width: 10, ), ), ), ), ), - Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - flex: 2, - child: Container( - decoration: BoxDecoration( - color: ColorsManager.graysColor, - borderRadius: BorderRadius.circular(10), - ), - child: - Expanded(child: Container(child: widget.widget)), + ), + Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: Container( + decoration: BoxDecoration( + color: ColorsManager.graysColor, + borderRadius: BorderRadius.circular(10), ), + child: Container(child: widget.widget), ), - Spacer(), - Expanded( - flex: 2, - child: Container( - padding: const EdgeInsets.all(5.0), - decoration: BoxDecoration( - color: ColorsManager.graysColor, - borderRadius: BorderRadius.circular(10), - ), - child: InkWell( - onTap: widget.onTap, - child: Center( - child: Container( - child: SizedBox( - child: Padding( - padding: const EdgeInsets.all(5), - child: Text(widget.formattedDate), - ), - )), + ), + const Spacer(), + Container( + padding: const EdgeInsets.all(5.0), + decoration: BoxDecoration( + color: ColorsManager.graysColor, + borderRadius: BorderRadius.circular(10), + ), + child: InkWell( + onTap: widget.onTap, + child: Center( + child: SizedBox( + child: Padding( + padding: const EdgeInsets.all(5), + child: Text(widget.formattedDate), ), ), ), ), - ], - ), - ) - ], - ), + ), + ], + ), + ) + ], ), ], ), @@ -284,4 +275,3 @@ class EnergyData { final String time; final double consumption; } -// \ No newline at end of file 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 82c28ddf..635f44ea 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 @@ -29,14 +29,13 @@ class SmartPowerDeviceControl extends StatelessWidget if (state is SmartPowerLoading) { return const Center(child: CircularProgressIndicator()); - } else if (state is SmartPowerLoadBatchControll) { + } else if (state is GetDeviceStatus) { return _buildStatusControls( currentPage: _blocProvider.currentPage, context: context, blocProvider: _blocProvider, ); } else if (state is FilterRecordsState) { - // Handle the state when the records are filtered return _buildStatusControls( currentPage: _blocProvider.currentPage, context: context, @@ -103,14 +102,14 @@ class SmartPowerDeviceControl extends StatelessWidget ], ), ), - SizedBox( + const SizedBox( height: 10, ), PhaseWidget( phaseData: blocProvider.phaseData, ), Container( - padding: EdgeInsets.only( + padding: const EdgeInsets.only( top: 10, left: 20, right: 20, @@ -136,7 +135,7 @@ class SmartPowerDeviceControl extends StatelessWidget onPressed: () { blocProvider.add(SmartPowerArrowPressedEvent(-1)); _pageController.previousPage( - duration: Duration(milliseconds: 300), + duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, ); }, @@ -149,14 +148,14 @@ class SmartPowerDeviceControl extends StatelessWidget : currentPage == 2 ? 'Phase B' : 'Phase C', - style: TextStyle(fontSize: 18), + style: const TextStyle(fontSize: 18), ), IconButton( - icon: Icon(Icons.arrow_right), + icon: const Icon(Icons.arrow_right), onPressed: () { blocProvider.add(SmartPowerArrowPressedEvent(1)); _pageController.nextPage( - duration: Duration(milliseconds: 300), + duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, ); }, @@ -164,7 +163,7 @@ class SmartPowerDeviceControl extends StatelessWidget ], ), ), - SizedBox( + const SizedBox( height: 10, ), Expanded( @@ -173,9 +172,11 @@ class SmartPowerDeviceControl extends StatelessWidget onPageChanged: (int page) { blocProvider.add(SmartPowerPageChangedEvent(page)); }, + physics: const NeverScrollableScrollPhysics(), children: [ EnergyConsumptionPage( - formattedDate: blocProvider.formattedDate, + formattedDate: + '${blocProvider.formattedDate}${blocProvider.endChartDate}', onTap: () { blocProvider.add(SelectDateEvent(context: context)); blocProvider.add(FilterRecordsByDateEvent( @@ -201,7 +202,7 @@ class SmartPowerDeviceControl extends StatelessWidget EnergyData('11:00 AM', 4.0), ], totalConsumption: 10000, - date: '10/08/2024', + date: blocProvider.formattedDate, ), EnergyConsumptionPage( formattedDate: blocProvider.formattedDate, @@ -226,7 +227,7 @@ class SmartPowerDeviceControl extends StatelessWidget EnergyData('11:00 AM', 4.0), ], totalConsumption: 10000, - date: '10/08/2024', + date: blocProvider.formattedDate, ), EnergyConsumptionPage( formattedDate: blocProvider.formattedDate, @@ -251,7 +252,7 @@ class SmartPowerDeviceControl extends StatelessWidget EnergyData('11:00 AM', 6.0), ], totalConsumption: 10000, - date: '10/08/2024', + date: blocProvider.formattedDate, ), ], ), diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index 82a06b18..2ee5f9cd 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -205,7 +205,6 @@ class DevicesManagementApi { queryParameters: queryParameters, showServerMessage: true, expectedResponseModel: (json) { - print('object======$json'); return json; }, );