From 9b0e6ff89841a1f45a7f50ea2c1a0a3898f4a648 Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 20 Oct 2024 16:36:45 +0300 Subject: [PATCH 01/26] power_clamp --- .../helper/route_controls_based_code.dart | 12 ++ .../power_clamp/bloc/smart_power_bloc.dart | 171 +++++++++++++++++ .../power_clamp/bloc/smart_power_event.dart | 59 ++++++ .../power_clamp/bloc/smart_power_state.dart | 56 ++++++ .../models/wall_light_status_model.dart | 47 +++++ .../power_clamp/view/power_chart.dart | 177 ++++++++++++++++++ .../power_clamp/view/power_info_card.dart | 84 +++++++++ .../view/smart_power_device_control.dart | 67 +++++++ .../view/wall_light_batch_control.dart | 92 +++++++++ .../shared/device_batch_control_dialog.dart | 3 +- pubspec.lock | 32 ++-- pubspec.yaml | 1 + 12 files changed, 788 insertions(+), 13 deletions(-) create mode 100644 lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart create mode 100644 lib/pages/device_managment/power_clamp/bloc/smart_power_event.dart create mode 100644 lib/pages/device_managment/power_clamp/bloc/smart_power_state.dart create mode 100644 lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart create mode 100644 lib/pages/device_managment/power_clamp/view/power_chart.dart create mode 100644 lib/pages/device_managment/power_clamp/view/power_info_card.dart create mode 100644 lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart create mode 100644 lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart diff --git a/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart b/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart index d4b5b21a..6e506a8e 100644 --- a/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart +++ b/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart @@ -18,6 +18,7 @@ import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_do import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/view/one_gang_glass_batch_control_view.dart'; import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_batch_control.dart'; import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/smart_power_device_control.dart'; import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/view/three_gang_glass_switch_batch_control_view.dart'; import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/view/three_gang_glass_switch_control_view.dart'; import 'package:syncrow_web/pages/device_managment/three_gang_switch/view/living_room_batch_controls.dart'; @@ -94,6 +95,10 @@ mixin RouteControlsBasedCode { return WaterLeakView( deviceId: device.uuid!, ); + case 'PC': + return SmartPowerDeviceControl( + deviceId: device.uuid!, + ); default: return const SizedBox(); } @@ -224,6 +229,13 @@ mixin RouteControlsBasedCode { .map((e) => e.uuid!) .toList(), ); + case 'PC': + return WaterLeakBatchControlView( + deviceIds: devices + .where((e) => (e.productType == 'PC')) + .map((e) => e.uuid!) + .toList(), + ); default: return const SizedBox(); } 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 new file mode 100644 index 00000000..d3eb7120 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/bloc/smart_power_bloc.dart @@ -0,0 +1,171 @@ +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'; +import 'package:syncrow_web/services/devices_mang_api.dart'; + +class SmartPowerBloc extends Bloc { + SmartPowerBloc({required this.deviceId}) : super(SmartPowerInitial()) { + on(_onFetchDeviceStatus); + on(_onControl); + on(_onFetchBatchStatus); + on(_onBatchControl); + on(_onFactoryReset); + } + + late SmartPowerStatusModel deviceStatus; + final String deviceId; + Timer? _timer; + + FutureOr _onFetchDeviceStatus( + SmartPowerFetchDeviceEvent event, Emitter emit) async { + emit(SmartPowerLoading()); + try { + // final status = + // await DevicesManagementApi().getDeviceStatus(event.deviceId); + // deviceStatus = + // SmartPowerStatusModel.fromJson(event.deviceId, status.status); + 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); + emit(SmartPowerStatusLoaded(deviceStatus)); + } catch (e) { + emit(SmartPowerError(e.toString())); + } + } + + @override + Future close() { + _timer?.cancel(); + return super.close(); + } + + FutureOr _onBatchControl( + SmartPowerBatchControl event, Emitter emit) async { + final oldValue = _getValueByCode(event.code); + + _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)); + } + } 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 new file mode 100644 index 00000000..15a034fc --- /dev/null +++ b/lib/pages/device_managment/power_clamp/bloc/smart_power_event.dart @@ -0,0 +1,59 @@ +import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart'; + +class SmartPowerEvent extends Equatable { + @override + List get props => []; +} + +class SmartPowerFetchDeviceEvent extends SmartPowerEvent { + final String deviceId; + + SmartPowerFetchDeviceEvent(this.deviceId); + + @override + List get props => [deviceId]; +} + +class SmartPowerControl extends SmartPowerEvent { + final String deviceId; + final String code; + final bool value; + + SmartPowerControl( + {required this.deviceId, required this.code, required this.value}); + + @override + List get props => [deviceId, code, value]; +} + +class SmartPowerFetchBatchEvent extends SmartPowerEvent { + final List devicesIds; + + SmartPowerFetchBatchEvent(this.devicesIds); + + @override + List get props => [devicesIds]; +} + +class SmartPowerBatchControl extends SmartPowerEvent { + final List devicesIds; + final String code; + final bool value; + + SmartPowerBatchControl( + {required this.devicesIds, required this.code, required this.value}); + + @override + List get props => [devicesIds, code, value]; +} + +class WallLightFactoryReset extends SmartPowerEvent { + final String deviceId; + final FactoryResetModel factoryReset; + + WallLightFactoryReset({required this.deviceId, required this.factoryReset}); + + @override + List get props => [deviceId, factoryReset]; +} 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 new file mode 100644 index 00000000..005f5c70 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/bloc/smart_power_state.dart @@ -0,0 +1,56 @@ +import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/wall_light_status_model.dart'; + +class SmartPowerState extends Equatable { + @override + List get props => []; +} + +class SmartPowerInitial extends SmartPowerState {} + +class SmartPowerLoading extends SmartPowerState {} + +class SmartPowerStatusLoaded extends SmartPowerState { + final SmartPowerStatusModel status; + + SmartPowerStatusLoaded(this.status); + + @override + List get props => [status]; +} + +class SmartPowerError extends SmartPowerState { + final String message; + + SmartPowerError(this.message); + + @override + List get props => [message]; +} + +class SmartPowerControlError extends SmartPowerState { + final String message; + + SmartPowerControlError(this.message); + + @override + List get props => [message]; +} + +class SmartPowerBatchControlError extends SmartPowerState { + final String message; + + SmartPowerBatchControlError(this.message); + + @override + List get props => [message]; +} + +class SmartPowerBatchStatusLoaded extends SmartPowerState { + final List status; + + SmartPowerBatchStatusLoaded(this.status); + + @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 new file mode 100644 index 00000000..15060492 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart @@ -0,0 +1,47 @@ +import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; + +class SmartPowerStatusModel { + final String uuid; + final bool switch1; + final int countDown; + + SmartPowerStatusModel({ + required this.uuid, + required this.switch1, + required this.countDown, + }); + + 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, + ); + } +} diff --git a/lib/pages/device_managment/power_clamp/view/power_chart.dart b/lib/pages/device_managment/power_clamp/view/power_chart.dart new file mode 100644 index 00000000..2cd4ce5b --- /dev/null +++ b/lib/pages/device_managment/power_clamp/view/power_chart.dart @@ -0,0 +1,177 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; + +class EnergyConsumptionPage extends StatefulWidget { + final List chartData; + final double totalConsumption; + final String date; + + EnergyConsumptionPage({ + required this.chartData, + required this.totalConsumption, + required this.date, + }); + + @override + _EnergyConsumptionPageState createState() => _EnergyConsumptionPageState(); +} + +class _EnergyConsumptionPageState extends State { + late List _chartData; + + @override + void initState() { + _chartData = widget.chartData; + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: 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; + }, + 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: true, + 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, + 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, + ), + ), + dotData: FlDotData( + show: false, + ), + isStrokeCapRound: true, + barWidth: 2, + ), + ], + borderData: FlBorderData( + show: false, + border: Border.all( + color: Color(0xff023DFE).withOpacity(0.7), + width: 10, + ), + ), + ), + ), + ), + ), + ], + ), + ); + } +} + +class EnergyData { + EnergyData(this.time, this.consumption); + final String time; + final double consumption; +} +// \ No newline at end of file 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 new file mode 100644 index 00000000..de90da4f --- /dev/null +++ b/lib/pages/device_managment/power_clamp/view/power_info_card.dart @@ -0,0 +1,84 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/painting.dart'; +import 'package:flutter_svg/flutter_svg.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; + +class PowerClampInfoCard extends StatelessWidget { + final String iconPath; + final String title; + final String value; + final String unit; + + const PowerClampInfoCard({ + Key? key, + required this.iconPath, + required this.title, + required this.value, + required this.unit, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Expanded( + child: Padding( + padding: const EdgeInsets.all(5.0), + child: Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(20), + ), + height: 55, + color: ColorsManager.graysColor, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Expanded( + child: 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, + ), + ), + 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, + ), + ), + ], + ), + ], + ), + ) + ], + ), + ), + ), + ); + } +} 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 new file mode 100644 index 00000000..2e6ee338 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/view/smart_power_device_control.dart @@ -0,0 +1,67 @@ +import 'package:flutter/material.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_chart.dart'; +import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; + +//Smart Power Clamp +class SmartPowerDeviceControl extends StatelessWidget + with HelperResponsiveLayout { + final String deviceId; + + const SmartPowerDeviceControl({super.key, required this.deviceId}); + @override + Widget build(BuildContext context) { + return _buildStatusControls( + context, + ); + + // 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); + 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', + ), + ); + } +} diff --git a/lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart b/lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart new file mode 100644 index 00000000..e1dabb61 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart @@ -0,0 +1,92 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart'; +import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_bloc.dart'; +import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_event.dart'; +import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_state.dart'; +import 'package:syncrow_web/pages/device_managment/one_gang_switch/models/wall_light_status_model.dart'; +import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart'; +import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart'; +import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart'; +import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; + +class WallLightBatchControlView extends StatelessWidget + with HelperResponsiveLayout { + const WallLightBatchControlView({super.key, required this.deviceIds}); + + final List deviceIds; + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => WallLightSwitchBloc(deviceId: deviceIds.first) + ..add(WallLightSwitchFetchBatchEvent(deviceIds)), + child: BlocBuilder( + builder: (context, state) { + if (state is WallLightSwitchLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is WallLightSwitchStatusLoaded) { + 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, WallLightStatusModel status) { + final isExtraLarge = isExtraLargeScreenSize(context); + final isLarge = isLargeScreenSize(context); + final isMedium = isMediumScreenSize(context); + return SizedBox( + child: GridView( + padding: const EdgeInsets.symmetric(horizontal: 50), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: isLarge || isExtraLarge + ? 3 + : isMedium + ? 2 + : 1, + mainAxisExtent: 140, + crossAxisSpacing: 12, + mainAxisSpacing: 12, + ), + children: [ + ToggleWidget( + value: status.switch1, + code: 'switch_1', + deviceId: deviceIds.first, + label: 'Wall Light', + onChange: (value) { + context.read().add( + WallLightSwitchBatchControl( + devicesIds: deviceIds, + code: 'switch_1', + value: value, + ), + ); + }, + ), + FirmwareUpdateWidget( + deviceId: deviceIds.first, + version: 12, + ), + FactoryResetWidget( + callFactoryReset: () { + context.read().add(WallLightFactoryReset( + deviceId: status.uuid, + factoryReset: FactoryResetModel(devicesUuid: deviceIds))); + }, + ), + ], + ), + ); + } +} diff --git a/lib/pages/device_managment/shared/device_batch_control_dialog.dart b/lib/pages/device_managment/shared/device_batch_control_dialog.dart index 5076ef76..d11b1701 100644 --- a/lib/pages/device_managment/shared/device_batch_control_dialog.dart +++ b/lib/pages/device_managment/shared/device_batch_control_dialog.dart @@ -7,7 +7,8 @@ import 'package:syncrow_web/pages/device_managment/all_devices/helper/route_cont import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; import 'package:syncrow_web/utils/color_manager.dart'; -class DeviceBatchControlDialog extends StatelessWidget with RouteControlsBasedCode { +class DeviceBatchControlDialog extends StatelessWidget + with RouteControlsBasedCode { final List devices; const DeviceBatchControlDialog({super.key, required this.devices}); diff --git a/pubspec.lock b/pubspec.lock index 2c9cb88c..fa61b407 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -137,6 +137,14 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" + fl_chart: + dependency: "direct main" + description: + name: fl_chart + sha256: "94307bef3a324a0d329d3ab77b2f0c6e5ed739185ffc029ed28c0f9b019ea7ef" + url: "https://pub.dev" + source: hosted + version: "0.69.0" flutter: dependency: "direct main" description: flutter @@ -292,18 +300,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.5" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: @@ -340,18 +348,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.11.1" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.12.0" nested: dependency: transitive description: @@ -561,10 +569,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.7.2" + version: "0.7.0" typed_data: dependency: transitive description: @@ -609,10 +617,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "14.2.5" + version: "14.2.1" web: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index dfeb1ff9..7742e4da 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,6 +49,7 @@ dependencies: intl: ^0.19.0 dropdown_search: ^5.0.6 flutter_dotenv: ^5.1.0 + fl_chart: ^0.69.0 dev_dependencies: flutter_test: From 3684ac4d2718f9a6b57253e7c85edc88b28c7dbc Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 21 Oct 2024 16:39:10 +0300 Subject: [PATCH 02/26] power_clamp --- assets/icons/frequency_icon.svg | 25 ++ assets/icons/power_active_icon.svg | 3 + assets/icons/speedo_meter.svg | 16 ++ assets/icons/volt-meter.svg | 26 ++ assets/icons/volt_meter_icon.svg | 26 ++ .../power_clamp/bloc/smart_power_bloc.dart | 168 ++++------- .../power_clamp/bloc/smart_power_event.dart | 9 + .../power_clamp/bloc/smart_power_state.dart | 3 +- .../models/wall_light_status_model.dart | 121 +++++--- .../power_clamp/view/phase_widget.dart | 124 ++++++++ .../power_clamp/view/power_chart.dart | 59 +++- .../power_clamp/view/power_info_card.dart | 76 +++-- .../view/smart_power_device_control.dart | 264 ++++++++++++++---- lib/services/devices_mang_api.dart | 47 +++- lib/utils/constants/api_const.dart | 4 +- lib/utils/constants/assets.dart | 9 + 16 files changed, 719 insertions(+), 261 deletions(-) create mode 100644 assets/icons/frequency_icon.svg create mode 100644 assets/icons/power_active_icon.svg create mode 100644 assets/icons/speedo_meter.svg create mode 100644 assets/icons/volt-meter.svg create mode 100644 assets/icons/volt_meter_icon.svg create mode 100644 lib/pages/device_managment/power_clamp/view/phase_widget.dart 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"; } From 97c3b90b76127f629e9f9e396da0f4d66751ac9c Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 21 Oct 2024 16:47:31 +0300 Subject: [PATCH 03/26] power_clamp --- .../device_managment/power_clamp/bloc/smart_power_bloc.dart | 2 +- .../device_managment/power_clamp/bloc/smart_power_state.dart | 2 +- .../{wall_light_status_model.dart => power_clamp_model.dart} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/pages/device_managment/power_clamp/models/{wall_light_status_model.dart => power_clamp_model.dart} (100%) 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 64e3fd50..88ce7bf9 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 @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_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/models/wall_light_status_model.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; import 'package:syncrow_web/services/devices_mang_api.dart'; class SmartPowerBloc extends Bloc { 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 9b60a8d3..7d705a72 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 @@ -1,5 +1,5 @@ import 'package:equatable/equatable.dart'; -import 'package:syncrow_web/pages/device_managment/power_clamp/models/wall_light_status_model.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; class SmartPowerState extends Equatable { @override diff --git a/lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart b/lib/pages/device_managment/power_clamp/models/power_clamp_model.dart similarity index 100% rename from lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart rename to lib/pages/device_managment/power_clamp/models/power_clamp_model.dart From b9ecae7068a2b2d2bc8cec73614e1bc6e260dd23 Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 21 Oct 2024 16:47:31 +0300 Subject: [PATCH 04/26] power_clamp --- .../device_managment/power_clamp/bloc/smart_power_bloc.dart | 2 +- .../device_managment/power_clamp/bloc/smart_power_state.dart | 2 +- .../{wall_light_status_model.dart => power_clamp_model.dart} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename lib/pages/device_managment/power_clamp/models/{wall_light_status_model.dart => power_clamp_model.dart} (100%) 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 64e3fd50..88ce7bf9 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 @@ -2,7 +2,7 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_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/models/wall_light_status_model.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; import 'package:syncrow_web/services/devices_mang_api.dart'; class SmartPowerBloc extends Bloc { 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 9b60a8d3..7d705a72 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 @@ -1,5 +1,5 @@ import 'package:equatable/equatable.dart'; -import 'package:syncrow_web/pages/device_managment/power_clamp/models/wall_light_status_model.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; class SmartPowerState extends Equatable { @override diff --git a/lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart b/lib/pages/device_managment/power_clamp/models/power_clamp_model.dart similarity index 100% rename from lib/pages/device_managment/power_clamp/models/wall_light_status_model.dart rename to lib/pages/device_managment/power_clamp/models/power_clamp_model.dart From bb5571a02d5640bfecb76a89d4a320b96b15a80b Mon Sep 17 00:00:00 2001 From: mohammad Date: Tue, 22 Oct 2024 10:18:49 +0300 Subject: [PATCH 05/26] power_clamp --- .../device_managment/power_clamp/bloc/smart_power_bloc.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 88ce7bf9..c2e69d39 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 @@ -58,7 +58,7 @@ class SmartPowerBloc extends Bloc { SmartPowerFetchBatchEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - final status = + await DevicesManagementApi().getBatchStatus(event.devicesIds); // deviceStatus = // SmartPowerStatusModel.fromJson(event.devicesIds.first, status.status); From f0c2560af2364fe316b604b6a7b40f0d7d444d2f Mon Sep 17 00:00:00 2001 From: mohammad Date: Tue, 22 Oct 2024 13:26:36 +0300 Subject: [PATCH 06/26] power_clamp --- .../power_clamp/view/smart_power_device_control.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 6945fde6..884a668a 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 @@ -91,7 +91,7 @@ class _SmartPowerDeviceControlState extends State { iconPath: Assets.powerActiveIcon, title: 'Active', value: blocProvider - .deviceStatus.status.general.dataPoints[0].value + .deviceStatus.status.general.dataPoints[2].value .toString(), unit: '', ), @@ -107,7 +107,7 @@ class _SmartPowerDeviceControlState extends State { iconPath: Assets.frequencyIcon, title: 'Frequency', value: blocProvider - .deviceStatus.status.general.dataPoints[2].value + .deviceStatus.status.general.dataPoints[4].value .toString(), unit: ' Hz', ), From bd7651fa8cf8bcd2c6984b778a3e02f9808d0659 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Wed, 23 Oct 2024 01:15:17 +0300 Subject: [PATCH 07/26] push scroll bar and design enhancment --- .../view/access_management.dart | 37 ++++- lib/pages/common/curtain_toggle.dart | 8 +- lib/pages/common/custom_table.dart | 131 ++++++++++-------- .../text_field/custom_web_textfield.dart | 47 +++---- .../ac/view/ac_device_control.dart | 6 +- .../widgets/device_managment_body.dart | 3 +- .../gateway/view/gateway_view.dart | 75 +++++++--- .../shared/device_control_dialog.dart | 5 +- .../shared/device_controls_container.dart | 27 ++-- lib/utils/theme/theme.dart | 1 + pubspec.lock | 8 ++ pubspec.yaml | 1 + 12 files changed, 218 insertions(+), 131 deletions(-) diff --git a/lib/pages/access_management/view/access_management.dart b/lib/pages/access_management/view/access_management.dart index 8a6fa022..caa5fe28 100644 --- a/lib/pages/access_management/view/access_management.dart +++ b/lib/pages/access_management/view/access_management.dart @@ -15,8 +15,8 @@ import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; -import 'package:syncrow_web/utils/style.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; +import 'package:syncrow_web/utils/style.dart'; import 'package:syncrow_web/web_layout/web_scaffold.dart'; class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { @@ -183,6 +183,14 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { isRequired: false, textFieldName: 'Name', description: '', + onSubmitted: (value) { + accessBloc.add(FilterDataEvent( + emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), + selectedTabIndex: BlocProvider.of(context).selectedIndex, + passwordName: accessBloc.passwordName.text.toLowerCase(), + startTime: accessBloc.effectiveTimeTimeStamp, + endTime: accessBloc.expirationTimeTimeStamp)); + }, ), ), const SizedBox(width: 15), @@ -194,6 +202,14 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { isRequired: false, textFieldName: 'Authorizer', description: '', + onSubmitted: (value) { + accessBloc.add(FilterDataEvent( + emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), + selectedTabIndex: BlocProvider.of(context).selectedIndex, + passwordName: accessBloc.passwordName.text.toLowerCase(), + startTime: accessBloc.effectiveTimeTimeStamp, + endTime: accessBloc.expirationTimeTimeStamp)); + }, ), ), const SizedBox(width: 15), @@ -239,12 +255,19 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { SizedBox( width: 300, child: CustomWebTextField( - controller: accessBloc.passwordName, - isRequired: true, - height: 40, - textFieldName: 'Name', - description: '', - ), + controller: accessBloc.passwordName, + isRequired: true, + height: 40, + textFieldName: 'Name', + description: '', + onSubmitted: (value) { + accessBloc.add(FilterDataEvent( + emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), + selectedTabIndex: BlocProvider.of(context).selectedIndex, + passwordName: accessBloc.passwordName.text.toLowerCase(), + startTime: accessBloc.effectiveTimeTimeStamp, + endTime: accessBloc.expirationTimeTimeStamp)); + }), ), DateTimeWebWidget( icon: Assets.calendarIcon, diff --git a/lib/pages/common/curtain_toggle.dart b/lib/pages/common/curtain_toggle.dart index 305ede03..7b1551c5 100644 --- a/lib/pages/common/curtain_toggle.dart +++ b/lib/pages/common/curtain_toggle.dart @@ -26,9 +26,12 @@ class CurtainToggle extends StatelessWidget { child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ + const SizedBox( + height: 10, + ), Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, children: [ ClipOval( child: Container( @@ -41,6 +44,9 @@ class CurtainToggle extends StatelessWidget { ), ), ), + const SizedBox( + width: 20, + ), SizedBox( height: 20, width: 35, diff --git a/lib/pages/common/custom_table.dart b/lib/pages/common/custom_table.dart index 5b6692ae..10171c33 100644 --- a/lib/pages/common/custom_table.dart +++ b/lib/pages/common/custom_table.dart @@ -4,6 +4,7 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_managment_bloc.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'; class DynamicTable extends StatefulWidget { final List headers; @@ -45,6 +46,8 @@ class DynamicTable extends StatefulWidget { class _DynamicTableState extends State { late List _selectedRows; bool _selectAll = false; + final ScrollController _verticalScrollController = ScrollController(); + final ScrollController _horizontalScrollController = ScrollController(); @override void initState() { @@ -102,68 +105,78 @@ class _DynamicTableState extends State { Widget build(BuildContext context) { return Container( decoration: widget.cellDecoration, - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: SizedBox( - width: widget.size.width, - child: Column( - children: [ - Container( - decoration: widget.headerDecoration ?? BoxDecoration(color: Colors.grey[200]), - child: Row( + child: Scrollbar( + controller: _verticalScrollController, + thumbVisibility: true, + trackVisibility: true, + child: Scrollbar( + controller: _horizontalScrollController, + thumbVisibility: false, + trackVisibility: false, + notificationPredicate: (notif) => notif.depth == 1, + child: SingleChildScrollView( + controller: _verticalScrollController, + child: SingleChildScrollView( + controller: _horizontalScrollController, + scrollDirection: Axis.horizontal, + child: SizedBox( + width: widget.size.width, + child: Column( children: [ - if (widget.withCheckBox) _buildSelectAllCheckbox(), - ...widget.headers.map((header) => _buildTableHeaderCell(header)), - ], - ), - ), - widget.isEmpty - ? Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, + Container( + decoration: widget.headerDecoration ?? + const BoxDecoration( + color: ColorsManager.boxColor, + ), + child: Row( children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.center, + if (widget.withCheckBox) _buildSelectAllCheckbox(), + ...widget.headers.map((header) => _buildTableHeaderCell(header)), + ], + ), + ), + widget.isEmpty + ? Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Column( + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ - SvgPicture.asset(Assets.emptyTable), - const SizedBox( - height: 15, + Column( + children: [ + SvgPicture.asset(Assets.emptyTable), + const SizedBox( + height: 15, + ), + Text( + widget.tableName == 'AccessManagement' ? 'No Password ' : 'No Devices', + style: Theme.of(context) + .textTheme + .bodySmall! + .copyWith(color: ColorsManager.grayColor), + ) + ], ), - Text( - // no password - widget.tableName == 'AccessManagement' ? 'No Password ' : 'No Devices', - style: - Theme.of(context).textTheme.bodySmall!.copyWith(color: ColorsManager.grayColor), - ) ], ), ], + ) + : Column( + children: List.generate(widget.data.length, (index) { + final row = widget.data[index]; + return Row( + children: [ + if (widget.withCheckBox) _buildRowCheckbox(index, widget.size.height * 0.08), + ...row.map((cell) => _buildTableCell(cell.toString(), widget.size.height * 0.08)), + ], + ); + }), ), - ], - ), - ) - : Expanded( - child: Container( - color: Colors.white, - child: ListView.builder( - shrinkWrap: true, - itemCount: widget.data.length, - itemBuilder: (context, index) { - final row = widget.data[index]; - return Row( - children: [ - if (widget.withCheckBox) _buildRowCheckbox(index, widget.size.height * 0.10), - ...row.map((cell) => _buildTableCell(cell.toString(), widget.size.height * 0.10)), - ], - ); - }, - ), - ), - ), - ], + ], + ), + ), + ), ), ), ), @@ -173,7 +186,6 @@ class _DynamicTableState extends State { Widget _buildSelectAllCheckbox() { return Container( width: 50, - padding: const EdgeInsets.all(8.0), decoration: const BoxDecoration( border: Border.symmetric( vertical: BorderSide(color: ColorsManager.boxDivider), @@ -198,6 +210,7 @@ class _DynamicTableState extends State { width: 1.0, ), ), + color: ColorsManager.whiteColors, ), alignment: Alignment.centerLeft, child: Center( @@ -219,15 +232,16 @@ class _DynamicTableState extends State { vertical: BorderSide(color: ColorsManager.boxDivider), ), ), + constraints: const BoxConstraints.expand(height: 40), alignment: Alignment.centerLeft, child: Padding( - padding: const EdgeInsets.all(8.0), + padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4), child: Text( title, - style: const TextStyle( + style: context.textTheme.titleSmall!.copyWith( + color: ColorsManager.grayColor, + fontSize: 12, fontWeight: FontWeight.w400, - fontSize: 13, - color: Color(0xFF999999), ), maxLines: 2, ), @@ -276,6 +290,7 @@ class _DynamicTableState extends State { width: 1.0, ), ), + color: Colors.white, ), alignment: Alignment.centerLeft, child: Text( @@ -286,7 +301,7 @@ class _DynamicTableState extends State { : (batteryLevel != null && batteryLevel > 20) ? ColorsManager.green : statusColor, - fontSize: 10, + fontSize: 13, fontWeight: FontWeight.w400), maxLines: 2, ), diff --git a/lib/pages/common/text_field/custom_web_textfield.dart b/lib/pages/common/text_field/custom_web_textfield.dart index 756463e2..d5c64e8d 100644 --- a/lib/pages/common/text_field/custom_web_textfield.dart +++ b/lib/pages/common/text_field/custom_web_textfield.dart @@ -13,6 +13,7 @@ class CustomWebTextField extends StatelessWidget { this.validator, this.hintText, this.height, + this.onSubmitted, }); final bool isRequired; @@ -22,6 +23,7 @@ class CustomWebTextField extends StatelessWidget { final String? Function(String?)? validator; final String? hintText; final double? height; + final ValueChanged? onSubmitted; @override Widget build(BuildContext context) { @@ -32,33 +34,29 @@ class CustomWebTextField extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - - Row( - children: [ - if (isRequired) - Text('* ', - style: Theme.of(context) - .textTheme.bodyMedium! - .copyWith(color: Colors.red), - ), + Row( + children: [ + if (isRequired) Text( - textFieldName, - style: Theme.of(context) - .textTheme.bodySmall! - .copyWith(color: Colors.black, fontSize: 13), + '* ', + style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: Colors.red), ), - ], - ), + Text( + textFieldName, + style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.black, fontSize: 13), + ), + ], + ), const SizedBox( width: 10, ), Expanded( child: Text( description ?? '', - style: Theme.of(context).textTheme.bodySmall!.copyWith( - fontSize: 9, - fontWeight: FontWeight.w400, - color: ColorsManager.textGray), + style: Theme.of(context) + .textTheme + .bodySmall! + .copyWith(fontSize: 9, fontWeight: FontWeight.w400, color: ColorsManager.textGray), ), ), ], @@ -68,26 +66,23 @@ class CustomWebTextField extends StatelessWidget { ), Container( height: height ?? 35, - decoration: containerDecoration.copyWith( - color: const Color(0xFFF5F6F7), - boxShadow: [ + decoration: containerDecoration.copyWith(color: const Color(0xFFF5F6F7), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.3), spreadRadius: 2, blurRadius: 3, offset: const Offset(1, 1), // changes position of shadow ), - ] - ), + ]), child: TextFormField( validator: validator, controller: controller, style: const TextStyle(color: Colors.black), decoration: textBoxDecoration()!.copyWith( errorStyle: const TextStyle(height: 0), - hintStyle: context.textTheme.titleSmall! - .copyWith(color: Colors.grey, fontSize: 12), + hintStyle: context.textTheme.titleSmall!.copyWith(color: Colors.grey, fontSize: 12), hintText: hintText ?? 'Please enter'), + onFieldSubmitted: onSubmitted, ), ), ], diff --git a/lib/pages/device_managment/ac/view/ac_device_control.dart b/lib/pages/device_managment/ac/view/ac_device_control.dart index 37d3a402..5197d722 100644 --- a/lib/pages/device_managment/ac/view/ac_device_control.dart +++ b/lib/pages/device_managment/ac/view/ac_device_control.dart @@ -40,7 +40,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout { : 1, mainAxisExtent: 140, crossAxisSpacing: 12, - mainAxisSpacing: 12, + mainAxisSpacing: 16, ), children: [ ToggleWidget( @@ -81,6 +81,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ IconButton( + padding: const EdgeInsets.all(0), onPressed: () {}, icon: const Icon( Icons.remove, @@ -108,6 +109,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout { ), Text('m', style: context.textTheme.bodySmall!.copyWith(color: ColorsManager.blackColor)), IconButton( + padding: const EdgeInsets.all(0), onPressed: () {}, icon: const Icon( Icons.add, @@ -127,7 +129,7 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout { deviceId: device.uuid!, code: 'child_lock', value: state.status.childLock, - label: 'Child Lock', + label: 'Lock', icon: state.status.childLock ? Assets.acLock : Assets.unlock, onChange: (value) { context.read().add( diff --git a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart index 2787c7b9..366775bf 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart @@ -8,7 +8,6 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_search_filters.dart'; import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart'; import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart'; -import 'package:syncrow_web/utils/extension/build_context_x.dart'; import 'package:syncrow_web/utils/format_date_time.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; import 'package:syncrow_web/utils/style.dart'; @@ -132,7 +131,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { context.read().add(SelectDevice(selectedDevice)); }, withCheckBox: true, - size: context.screenSize, + size: MediaQuery.of(context).size, uuidIndex: 2, headers: const [ 'Device Name', diff --git a/lib/pages/device_managment/gateway/view/gateway_view.dart b/lib/pages/device_managment/gateway/view/gateway_view.dart index 2bfc6822..d674e4d8 100644 --- a/lib/pages/device_managment/gateway/view/gateway_view.dart +++ b/lib/pages/device_managment/gateway/view/gateway_view.dart @@ -5,6 +5,7 @@ import 'package:syncrow_web/pages/device_managment/gateway/bloc/gate_way_bloc.da import 'package:syncrow_web/pages/device_managment/shared/device_controls_container.dart'; import 'package:syncrow_web/pages/visitor_password/model/device_model.dart'; import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/extension/build_context_x.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; class GateWayControlsView extends StatelessWidget with HelperResponsiveLayout { @@ -25,25 +26,61 @@ class GateWayControlsView extends StatelessWidget with HelperResponsiveLayout { if (state is GatewayLoadingState) { return const Center(child: CircularProgressIndicator()); } else if (state is UpdateGatewayState) { - return GridView.builder( - padding: const EdgeInsets.symmetric(horizontal: 50), - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: isLarge || isExtraLarge - ? 3 - : isMedium - ? 2 - : 1, - mainAxisExtent: 140, - crossAxisSpacing: 12, - mainAxisSpacing: 12, - ), - itemCount: state.list.length, - itemBuilder: (context, index) { - final device = state.list[index]; - return _DeviceItem(device: device); - }, + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: const EdgeInsets.symmetric(horizontal: 50), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "Bluetooth Devices:", + style: context.textTheme.bodyMedium!.copyWith( + color: ColorsManager.grayColor, + ), + ), + const SizedBox(height: 12), + Text( + "No devices found", + style: context.textTheme.bodySmall!.copyWith( + color: ColorsManager.blackColor, + ), + ), + const SizedBox(height: 30), + Text( + "ZigBee Devices:", + style: context.textTheme.bodyMedium!.copyWith( + color: ColorsManager.grayColor, + ), + ), + ], + ), + ), + const SizedBox(height: 12), + GridView.builder( + padding: const EdgeInsets.symmetric(horizontal: 50), + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: isLarge || isExtraLarge + ? 3 + : isMedium + ? 2 + : 1, + mainAxisExtent: 140, + crossAxisSpacing: 12, + mainAxisSpacing: 12, + ), + itemCount: state.list.length, + itemBuilder: (context, index) { + final device = state.list[index]; + return _DeviceItem(device: device); + }, + ), + ], ); } else { return const Center(child: Text('Error fetching status')); diff --git a/lib/pages/device_managment/shared/device_control_dialog.dart b/lib/pages/device_managment/shared/device_control_dialog.dart index 14878a46..d7c592d6 100644 --- a/lib/pages/device_managment/shared/device_control_dialog.dart +++ b/lib/pages/device_managment/shared/device_control_dialog.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/helper/route_controls_based_code.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; +import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/format_date_time.dart'; @@ -31,7 +32,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode { children: [ const SizedBox(), Text( - device.productName ?? 'Device Control', + getBatchDialogName(device), style: TextStyle( fontWeight: FontWeight.bold, fontSize: 22, @@ -64,7 +65,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode { ), const SizedBox(height: 20), _buildDeviceInfoSection(), - const SizedBox(height: 20), + //const SizedBox(height: 20), //// BUILD DEVICE CONTROLS /// //// ROUTE TO SPECIFIC CONTROL VIEW BASED ON DEVICE CATEGORY diff --git a/lib/pages/device_managment/shared/device_controls_container.dart b/lib/pages/device_managment/shared/device_controls_container.dart index 4f1dea59..888563da 100644 --- a/lib/pages/device_managment/shared/device_controls_container.dart +++ b/lib/pages/device_managment/shared/device_controls_container.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:syncrow_web/utils/color_manager.dart'; class DeviceControlsContainer extends StatelessWidget { const DeviceControlsContainer({required this.child, this.padding, super.key}); @@ -8,21 +7,21 @@ class DeviceControlsContainer extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - decoration: BoxDecoration( + return Card( + shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(20), - color: ColorsManager.greyColor.withOpacity(0.2), - - // boxShadow: [ - // BoxShadow( - // color: ColorsManager.blackColor.withOpacity(0.05), - // blurRadius: 6.0, - // offset: const Offset(0, 5), - // spreadRadius: 0) - // ], ), - padding: EdgeInsets.all(padding ?? 12), - child: child, + elevation: 3, + surfaceTintColor: Colors.transparent, + child: Container( + decoration: BoxDecoration( + color: Colors.grey.shade100, + borderRadius: BorderRadius.circular(20), + ), + padding: + EdgeInsets.symmetric(vertical: padding ?? 10, horizontal: padding ?? 16), //EdgeInsets.all(padding ?? 12), + child: child, + ), ); } } diff --git a/lib/utils/theme/theme.dart b/lib/utils/theme/theme.dart index 413f3243..5ac61afa 100644 --- a/lib/utils/theme/theme.dart +++ b/lib/utils/theme/theme.dart @@ -3,6 +3,7 @@ import 'package:syncrow_web/utils/color_manager.dart'; final myTheme = ThemeData( fontFamily: 'Aftika', + useMaterial3: true, textTheme: const TextTheme( bodySmall: TextStyle( fontSize: 13, diff --git a/pubspec.lock b/pubspec.lock index 2c9cb88c..155d063b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -613,6 +613,14 @@ packages: url: "https://pub.dev" source: hosted version: "14.2.5" + vs_scrollbar: + dependency: "direct main" + description: + name: vs_scrollbar + sha256: "6a2df5e2597064e8dbb8fc3679065d8e748d711fa979f045328c98b7100b1665" + url: "https://pub.dev" + source: hosted + version: "1.0.0" web: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index dfeb1ff9..6c74f448 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,6 +49,7 @@ dependencies: intl: ^0.19.0 dropdown_search: ^5.0.6 flutter_dotenv: ^5.1.0 + vs_scrollbar: ^1.0.0 dev_dependencies: flutter_test: From 1c9943cfdb3630b44c92d7f1fee01853a4052cc7 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Wed, 23 Oct 2024 02:40:44 +0300 Subject: [PATCH 08/26] finilizing the alert dialog for logut --- assets/icons/account_setting.svg | 6 + assets/icons/logo-grey.svg | 4 + assets/icons/settings.svg | 4 + assets/icons/sign_out.svg | 3 + lib/utils/constants/assets.dart | 12 ++ lib/utils/user_drop_down_menu.dart | 224 +++++++++++++++++++++++++++++ lib/web_layout/web_app_bar.dart | 125 ++++++++-------- 7 files changed, 315 insertions(+), 63 deletions(-) create mode 100644 assets/icons/account_setting.svg create mode 100644 assets/icons/logo-grey.svg create mode 100644 assets/icons/settings.svg create mode 100644 assets/icons/sign_out.svg create mode 100644 lib/utils/user_drop_down_menu.dart diff --git a/assets/icons/account_setting.svg b/assets/icons/account_setting.svg new file mode 100644 index 00000000..0b27b849 --- /dev/null +++ b/assets/icons/account_setting.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/assets/icons/logo-grey.svg b/assets/icons/logo-grey.svg new file mode 100644 index 00000000..4f835d2d --- /dev/null +++ b/assets/icons/logo-grey.svg @@ -0,0 +1,4 @@ + + + + diff --git a/assets/icons/settings.svg b/assets/icons/settings.svg new file mode 100644 index 00000000..c626454d --- /dev/null +++ b/assets/icons/settings.svg @@ -0,0 +1,4 @@ + + + + diff --git a/assets/icons/sign_out.svg b/assets/icons/sign_out.svg new file mode 100644 index 00000000..5980d13e --- /dev/null +++ b/assets/icons/sign_out.svg @@ -0,0 +1,3 @@ + + + diff --git a/lib/utils/constants/assets.dart b/lib/utils/constants/assets.dart index 4ac64bb6..14f7a15e 100644 --- a/lib/utils/constants/assets.dart +++ b/lib/utils/constants/assets.dart @@ -168,4 +168,16 @@ class Assets { //assets/icons/2gang.svg static const String twoGang = 'assets/icons/2gang.svg'; + + //assets/icons/account_setting.svg + static const String accountSetting = 'assets/icons/account_setting.svg'; + + //assets/icons/settings.svg + static const String settings = 'assets/icons/settings.svg'; + + //assets/icons/sign_out.svg + static const String signOut = 'assets/icons/sign_out.svg'; + + //assets/icons/logo_grey.svg + static const String logoGrey = 'assets/icons/logo-grey.svg'; } diff --git a/lib/utils/user_drop_down_menu.dart b/lib/utils/user_drop_down_menu.dart new file mode 100644 index 00000000..dab01fd8 --- /dev/null +++ b/lib/utils/user_drop_down_menu.dart @@ -0,0 +1,224 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:go_router/go_router.dart'; +import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart'; +import 'package:syncrow_web/pages/auth/model/user_model.dart'; +import 'package:syncrow_web/pages/common/buttons/default_button.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; +import 'package:syncrow_web/utils/constants/routes_const.dart'; +import 'package:syncrow_web/utils/extension/build_context_x.dart'; + +class UserDropdownMenu extends StatefulWidget { + const UserDropdownMenu({super.key, required this.user}); + final UserModel? user; + + @override + _UserDropdownMenuState createState() => _UserDropdownMenuState(); +} + +class _UserDropdownMenuState extends State { + bool _isDropdownOpen = false; + + void _toggleDropdown() { + setState(() { + _isDropdownOpen = !_isDropdownOpen; + }); + } + + @override + Widget build(BuildContext context) { + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + GestureDetector( + onTap: () async { + _toggleDropdown(); + await _showPopupMenu(context); + setState(() { + _isDropdownOpen = false; + }); + }, + child: Transform.rotate( + angle: _isDropdownOpen ? -1.5708 : 1.5708, + child: const Icon( + Icons.arrow_forward_ios, + color: Colors.white, + size: 16, + ), + ), + ), + ], + ); + } + + Future _showPopupMenu(BuildContext context) async { + final RenderBox overlay = Overlay.of(context).context.findRenderObject() as RenderBox; + final RelativeRect position = RelativeRect.fromRect( + Rect.fromLTRB( + overlay.size.width, + 75, + 0, + overlay.size.height, + ), + Offset.zero & overlay.size, + ); + + await showMenu( + context: context, + position: position, + color: ColorsManager.whiteColors, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.only( + bottomRight: Radius.circular(10), + bottomLeft: Radius.circular(10), + ), + ), + items: [ + PopupMenuItem( + onTap: () {}, + child: ListTile( + leading: SvgPicture.asset(Assets.accountSetting), + title: Text( + "Account Settings", + style: context.textTheme.bodyMedium, + ), + ), + ), + PopupMenuItem( + onTap: () {}, + child: ListTile( + leading: SvgPicture.asset(Assets.settings), + title: Text( + "Settings", + style: context.textTheme.bodyMedium, + ), + ), + ), + PopupMenuItem( + onTap: () { + showDialog( + context: context, + builder: (BuildContext context) { + final size = MediaQuery.of(context).size; + return AlertDialog( + alignment: Alignment.center, + content: SizedBox( + height: 250, + width: 500, + child: Padding( + padding: const EdgeInsets.all(40), + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + SvgPicture.asset( + Assets.blackLogo, + height: 40, + width: 200, + ), + Padding( + padding: const EdgeInsets.only(top: 8.0), + child: Text( + 'Log out of your Syncrow account', + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + fontSize: 14, + fontWeight: FontWeight.w400, + color: Colors.black, + ), + ), + ), + ListTile( + leading: SizedBox.square( + dimension: 80, + child: CircleAvatar( + backgroundColor: ColorsManager.whiteColors, + child: SizedBox.square( + dimension: 78, + child: SvgPicture.asset( + Assets.logoGrey, + fit: BoxFit.fitHeight, + height: 80, + ), + ), + ), + ), + title: Text( + '${widget.user?.firstName ?? ''} ${widget.user?.lastName}', + style: Theme.of(context).textTheme.titleMedium!.copyWith( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 20, + ), + ), + subtitle: Text( + ' ${widget.user?.email}', + style: Theme.of(context).textTheme.bodySmall!.copyWith( + color: Colors.black, + ), + ), + ), + ], + ), + ), + ), + actionsAlignment: MainAxisAlignment.center, + actions: [ + SizedBox( + width: 200, + child: GestureDetector( + onTap: () { + context.pop(); + }, + child: DefaultButton( + backgroundColor: ColorsManager.boxColor, + elevation: 1, + child: Text( + 'Cancel', + style: Theme.of(context).textTheme.bodyMedium!.copyWith( + fontSize: 12, + color: Colors.black, + ), + ), + ), + ), + ), + const SizedBox( + height: 10, + ), + GestureDetector( + onTap: () { + AuthBloc.logout(); + context.go(RoutesConst.auth); + }, + child: SizedBox( + width: 200, + child: DefaultButton( + elevation: 1, + child: Text( + 'Logout', + style: + Theme.of(context).textTheme.bodyMedium!.copyWith(fontSize: 12, color: Colors.white), + ), + ), + ), + ), + ]); + }, + ); + }, + child: ListTile( + leading: SvgPicture.asset(Assets.signOut), + title: Text( + "Log Out", + style: context.textTheme.bodyMedium, + ), + ), + ), + ], + ).then((value) { + setState(() { + _isDropdownOpen = false; + }); + }); + } +} diff --git a/lib/web_layout/web_app_bar.dart b/lib/web_layout/web_app_bar.dart index 1052a23d..777b0931 100644 --- a/lib/web_layout/web_app_bar.dart +++ b/lib/web_layout/web_app_bar.dart @@ -1,14 +1,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:go_router/go_router.dart'; -import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart'; -import 'package:syncrow_web/pages/common/buttons/default_button.dart'; -import 'package:syncrow_web/pages/common/custom_dialog.dart'; +import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/home/bloc/home_bloc.dart'; import 'package:syncrow_web/pages/home/bloc/home_state.dart'; import 'package:syncrow_web/utils/color_manager.dart'; -import 'package:syncrow_web/utils/constants/routes_const.dart'; +import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; +import 'package:syncrow_web/utils/user_drop_down_menu.dart'; class WebAppBar extends StatefulWidget { final Widget? title; @@ -58,15 +56,15 @@ class _WebAppBarState extends State with HelperResponsiveLayout { if (widget.rightBody != null) widget.rightBody!, Row( children: [ - const SizedBox.square( + SizedBox.square( dimension: 40, child: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: ColorsManager.whiteColors, child: SizedBox.square( dimension: 35, - child: CircleAvatar( - backgroundColor: Colors.grey, - child: FlutterLogo(), + child: SvgPicture.asset( + Assets.logoGrey, + fit: BoxFit.cover, ), ), ), @@ -112,15 +110,15 @@ class _WebAppBarState extends State with HelperResponsiveLayout { const SizedBox( width: 10, ), - const SizedBox.square( + SizedBox.square( dimension: 40, child: CircleAvatar( - backgroundColor: Colors.white, + backgroundColor: ColorsManager.whiteColors, child: SizedBox.square( dimension: 35, - child: CircleAvatar( - backgroundColor: Colors.grey, - child: FlutterLogo(), + child: SvgPicture.asset( + Assets.logoGrey, + fit: BoxFit.cover, ), ), ), @@ -136,54 +134,55 @@ class _WebAppBarState extends State with HelperResponsiveLayout { const SizedBox( width: 10, ), - GestureDetector( - onTap: () { - showCustomDialog( - context: context, - barrierDismissible: true, - title: 'Logout', - message: 'Are you sure you want to logout?', - actions: [ - GestureDetector( - onTap: () { - AuthBloc.logout(); - context.go(RoutesConst.auth); - }, - child: DefaultButton( - child: Text( - 'Ok', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith(fontSize: 12, color: Colors.white), - ), - ), - ), - const SizedBox( - height: 10, - ), - GestureDetector( - onTap: () { - context.pop(); - }, - child: DefaultButton( - child: Text( - 'Cancel', - style: Theme.of(context) - .textTheme - .bodyMedium! - .copyWith(fontSize: 12, color: Colors.white), - ), - ), - ), - ], - ); - }, - child: const Icon( - Icons.logout, - color: ColorsManager.whiteColors, - ), - ) + UserDropdownMenu(user: user), + // GestureDetector( + // onTap: () { + // showCustomDialog( + // context: context, + // barrierDismissible: true, + // title: 'Logout', + // message: 'Are you sure you want to logout?', + // actions: [ + // GestureDetector( + // onTap: () { + // AuthBloc.logout(); + // context.go(RoutesConst.auth); + // }, + // child: DefaultButton( + // child: Text( + // 'Ok', + // style: Theme.of(context) + // .textTheme + // .bodyMedium! + // .copyWith(fontSize: 12, color: Colors.white), + // ), + // ), + // ), + // const SizedBox( + // height: 10, + // ), + // GestureDetector( + // onTap: () { + // context.pop(); + // }, + // child: DefaultButton( + // child: Text( + // 'Cancel', + // style: Theme.of(context) + // .textTheme + // .bodyMedium! + // .copyWith(fontSize: 12, color: Colors.white), + // ), + // ), + // ), + // ], + // ); + // }, + // child: const Icon( + // Icons.logout, + // color: ColorsManager.whiteColors, + // ), + // ) ], ), ], From 0b153918686fe59ebbaa4792ceed9d0a2662bade Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Wed, 23 Oct 2024 11:56:48 +0300 Subject: [PATCH 09/26] push logout dialog design --- lib/utils/user_drop_down_menu.dart | 77 ++++++++++++++++++------------ 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/lib/utils/user_drop_down_menu.dart b/lib/utils/user_drop_down_menu.dart index dab01fd8..3a0c4194 100644 --- a/lib/utils/user_drop_down_menu.dart +++ b/lib/utils/user_drop_down_menu.dart @@ -104,20 +104,20 @@ class _UserDropdownMenuState extends State { return AlertDialog( alignment: Alignment.center, content: SizedBox( - height: 250, - width: 500, + height: 200, + width: 400, child: Padding( - padding: const EdgeInsets.all(40), + padding: const EdgeInsets.only(top: 24, left: 24, right: 24), child: Column( mainAxisAlignment: MainAxisAlignment.start, children: [ - SvgPicture.asset( + Image.asset( Assets.blackLogo, height: 40, width: 200, ), Padding( - padding: const EdgeInsets.only(top: 8.0), + padding: const EdgeInsets.only(top: 16), child: Text( 'Log out of your Syncrow account', style: Theme.of(context).textTheme.bodyMedium!.copyWith( @@ -127,35 +127,50 @@ class _UserDropdownMenuState extends State { ), ), ), - ListTile( - leading: SizedBox.square( - dimension: 80, - child: CircleAvatar( - backgroundColor: ColorsManager.whiteColors, - child: SizedBox.square( - dimension: 78, - child: SvgPicture.asset( - Assets.logoGrey, - fit: BoxFit.fitHeight, - height: 80, + const SizedBox( + height: 16, + ), + Row( + children: [ + SizedBox.square( + dimension: 80, + child: CircleAvatar( + backgroundColor: ColorsManager.whiteColors, + child: SizedBox.square( + dimension: 78, + child: SvgPicture.asset( + Assets.logoGrey, + fit: BoxFit.fitHeight, + height: 80, + ), ), ), ), - ), - title: Text( - '${widget.user?.firstName ?? ''} ${widget.user?.lastName}', - style: Theme.of(context).textTheme.titleMedium!.copyWith( - color: Colors.black, - fontWeight: FontWeight.bold, - fontSize: 20, - ), - ), - subtitle: Text( - ' ${widget.user?.email}', - style: Theme.of(context).textTheme.bodySmall!.copyWith( - color: Colors.black, - ), - ), + const SizedBox( + width: 16, + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '${widget.user?.firstName ?? ''} ${widget.user?.lastName}', + style: Theme.of(context).textTheme.titleMedium!.copyWith( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 20, + ), + ), + Text( + ' ${widget.user?.email}', + style: Theme.of(context).textTheme.bodySmall!.copyWith( + color: Colors.black, + ), + ), + ], + ), + ), + ], ), ], ), From 76fbfd2d95aa85251010dfb883f4d7a5812ba686 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Wed, 23 Oct 2024 13:08:34 +0300 Subject: [PATCH 10/26] Removed vs_scrollbar package --- pubspec.lock | 8 -------- pubspec.yaml | 1 - 2 files changed, 9 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 155d063b..2c9cb88c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -613,14 +613,6 @@ packages: url: "https://pub.dev" source: hosted version: "14.2.5" - vs_scrollbar: - dependency: "direct main" - description: - name: vs_scrollbar - sha256: "6a2df5e2597064e8dbb8fc3679065d8e748d711fa979f045328c98b7100b1665" - url: "https://pub.dev" - source: hosted - version: "1.0.0" web: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6c74f448..dfeb1ff9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -49,7 +49,6 @@ dependencies: intl: ^0.19.0 dropdown_search: ^5.0.6 flutter_dotenv: ^5.1.0 - vs_scrollbar: ^1.0.0 dev_dependencies: flutter_test: From 9b4e687e9a48d6c657df0979d7eedc9176ca4df6 Mon Sep 17 00:00:00 2001 From: mohammad Date: Thu, 24 Oct 2024 15:03:19 +0300 Subject: [PATCH 11/26] power_clamp_functionality --- .../power_clamp/bloc/smart_power_bloc.dart | 643 +++++++++++++++++- .../power_clamp/bloc/smart_power_event.dart | 27 +- .../power_clamp/bloc/smart_power_state.dart | 17 +- .../power_clamp/models/device_event.dart | 23 + .../power_clamp/view/power_chart.dart | 301 ++++---- .../view/smart_power_device_control.dart | 243 ++++--- 6 files changed, 981 insertions(+), 273 deletions(-) create mode 100644 lib/pages/device_managment/power_clamp/models/device_event.dart 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 c2e69d39..d36f0c74 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,28 +1,218 @@ import 'dart:async'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:intl/intl.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/device_event.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_chart.dart'; import 'package:syncrow_web/services/devices_mang_api.dart'; class SmartPowerBloc extends Bloc { SmartPowerBloc({required this.deviceId}) : super(SmartPowerInitial()) { on(_onFetchDeviceStatus); - // on(_onControl); + on(_onArrowPressed); on(_onFetchBatchStatus); + on(_onPageChanged); on(_onBatchControl); - // on(_onFactoryReset); + on(_filterRecordsByDate); + on(checkDayMonthYearSelected); + // SelectDateEvent } late PowerClampModel deviceStatus; final String deviceId; Timer? _timer; List> phaseData = []; + int currentPage = 0; + + List record = [ + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:13'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:13'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:13'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-11 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-11 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-12 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-13 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-14 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-15 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-16 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-17 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-18 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-19 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-20 11:14:13'), + value: '2284'), + ]; + FutureOr _onFetchDeviceStatus( SmartPowerFetchDeviceEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - var status = await DevicesManagementApi().getPowerClampInfo(event.deviceId); + var status = + await DevicesManagementApi().getPowerClampInfo(event.deviceId); deviceStatus = PowerClampModel.fromJson(status); phaseData = [ @@ -48,21 +238,30 @@ class SmartPowerBloc extends Bloc { 'powerFactor': '${deviceStatus.status.phaseC.dataPoints[3].value}', }, ]; - emit(SmartPowerStatusLoaded(deviceStatus)); + emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); } catch (e) { emit(SmartPowerError(e.toString())); } } + FutureOr _onArrowPressed( + SmartPowerArrowPressedEvent event, Emitter emit) { + currentPage = (currentPage + event.direction + 4) % 4; + emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + } + + FutureOr _onPageChanged( + SmartPowerPageChangedEvent event, Emitter emit) { + currentPage = event.page; + emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + } + Future _onFetchBatchStatus( SmartPowerFetchBatchEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - - await DevicesManagementApi().getBatchStatus(event.devicesIds); - // deviceStatus = - // SmartPowerStatusModel.fromJson(event.devicesIds.first, status.status); - emit(SmartPowerStatusLoaded(deviceStatus)); + await DevicesManagementApi().getBatchStatus(event.devicesIds); + emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); } catch (e) { emit(SmartPowerError(e.toString())); } @@ -76,30 +275,408 @@ class SmartPowerBloc extends Bloc { FutureOr _onBatchControl( SmartPowerBatchControl event, Emitter emit) async { - // final oldValue = _getValueByCode(event.code); - - // _updateLocalValue(event.code, event.value); - - 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())); - } - } + emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); } - + List filteredRecords = []; + + int currentIndex = 0; + final List views = ['Day', 'Month', 'Year']; + + Widget dateSwitcher() { + void switchView(int direction) { + currentIndex = (currentIndex + direction + views.length) % views.length; + } + + return StatefulBuilder( + builder: (BuildContext context, StateSetter setState) { + return Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + IconButton( + icon: const Icon(Icons.arrow_left), + onPressed: () { + setState(() { + switchView(-1); + }); + }, + ), + Text( + views[currentIndex], + style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500), + ), + IconButton( + icon: const Icon(Icons.arrow_right), + onPressed: () { + setState(() { + switchView(1); + }); + }, + ), + ], + ); + }, + ); + } + + Future selectMonthAndYear(BuildContext context) async { + int selectedYear = DateTime.now().year; + int selectedMonth = DateTime.now().month; + + FixedExtentScrollController yearController = + FixedExtentScrollController(initialItem: selectedYear - 1905); + FixedExtentScrollController monthController = + FixedExtentScrollController(initialItem: selectedMonth - 1); + + return await showDialog( + context: context, + builder: (BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + color: Colors.white, + height: 350, + width: 350, + child: Column( + children: [ + const Padding( + padding: EdgeInsets.all(16.0), + child: Text( + 'Select Month and Year', + style: + TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + ), + const Divider(), + Expanded( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Spacer(), + Expanded( + child: ListWheelScrollView.useDelegate( + controller: yearController, + overAndUnderCenterOpacity: 0.2, + itemExtent: 50, + onSelectedItemChanged: (index) { + selectedYear = 1905 + index; + }, + childDelegate: ListWheelChildBuilderDelegate( + builder: (context, index) { + return Center( + child: Text( + (1905 + index).toString(), + style: const TextStyle(fontSize: 18), + ), + ); + }, + childCount: 200, + ), + ), + ), + Expanded( + flex: 2, + child: ListWheelScrollView.useDelegate( + controller: monthController, + overAndUnderCenterOpacity: 0.2, + itemExtent: 50, + onSelectedItemChanged: (index) { + selectedMonth = index + 1; + }, + childDelegate: ListWheelChildBuilderDelegate( + builder: (context, index) { + return Center( + child: Text( + DateFormat.MMMM() + .format(DateTime(0, index + 1)), + style: const TextStyle(fontSize: 18), + ), + ); + }, + childCount: 12, + ), + ), + ), + const Spacer(), + ], + ), + ), + const Divider(), + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16.0, vertical: 8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TextButton( + child: const Text('Cancel'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + TextButton( + child: const Text('OK'), + onPressed: () { + final selectedDateTime = + DateTime(selectedYear, selectedMonth); + Navigator.of(context).pop(selectedDateTime); + }, + ), + ], + ), + ), + ], + ), + ), + ], + ); + }, + ); + } + + Future selectYear(BuildContext context) async { + int selectedYear = DateTime.now().year; + FixedExtentScrollController yearController = + FixedExtentScrollController(initialItem: selectedYear - 1905); + + return await showDialog( + context: context, + builder: (BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + color: Colors.white, + height: 350, + width: 350, + child: Column( + children: [ + const Padding( + padding: EdgeInsets.all(16.0), + child: Text( + 'Select Year', + style: + TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + ), + ), + const Divider(), + Expanded( + child: ListWheelScrollView.useDelegate( + controller: yearController, + overAndUnderCenterOpacity: 0.2, + itemExtent: 50, + onSelectedItemChanged: (index) { + selectedYear = 1905 + index; + }, + childDelegate: ListWheelChildBuilderDelegate( + builder: (context, index) { + return Center( + child: Text( + (1905 + index).toString(), + style: const TextStyle(fontSize: 18), + ), + ); + }, + childCount: 200, + ), + ), + ), + const Divider(), + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16.0, vertical: 8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TextButton( + child: const Text('Cancel'), + onPressed: () { + 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 + }, + ), + ], + ), + ), + ], + ), + ), + ], + ); + }, + ); + } + + Future dayMonthYearPicker({ + required BuildContext context, + }) async { + DateTime selectedDate = DateTime.now(); // Default selected date + + return await showDialog( + context: context, + builder: (BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + color: Colors.white, + height: 350, + width: 350, + child: Column( + children: [ + Expanded( + child: CupertinoDatePicker( + mode: CupertinoDatePickerMode.date, + initialDateTime: DateTime.now(), + minimumYear: 1900, + maximumYear: DateTime.now().year, + onDateTimeChanged: (DateTime newDateTime) { + selectedDate = + newDateTime; // Update the selected date when changed + }, + ), + ), + const Divider(), + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16.0, vertical: 8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + TextButton( + child: const Text('Cancel'), + onPressed: () { + Navigator.of(context) + .pop(); // Dismiss the modal without returning a value + }, + ), + TextButton( + child: const Text('OK'), + onPressed: () { + Navigator.of(context) + .pop(selectedDate); // Return the selected date + }, + ), + ], + ), + ), + ], + ), + ), + ], + ); + }, + ); + } + + DateTime? dateTime = DateTime.now(); + String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now()); + void checkDayMonthYearSelected( + SelectDateEvent event, Emitter emit) async { + // emit(SmartPowerLoading()); + + if (currentIndex == 0) { + await dayMonthYearPicker(context: event.context).then( + (newDate) { + if (newDate != null) { + dateTime = newDate; + formattedDate = DateFormat('yyyy/MM/dd').format(dateTime!); + + add(FilterRecordsByDateEvent( + selectedDate: dateTime!, + viewType: views[currentIndex], + )); + } + }, + ); + } else if (currentIndex == 1) { + await selectMonthAndYear(event.context).then( + (newDate) { + if (newDate != null) { + dateTime = newDate; + formattedDate = DateFormat('yyyy-MM').format(dateTime!); + + add(FilterRecordsByDateEvent( + selectedDate: dateTime!, + viewType: views[currentIndex], + )); + } + }, + ); + } else if (currentIndex == 2) { + await selectYear(event.context).then( + (newDate) { + if (newDate != null) { + dateTime = newDate; + formattedDate = DateFormat('yyyy').format(dateTime!); + + add(FilterRecordsByDateEvent( + selectedDate: dateTime!, + viewType: views[currentIndex], + )); + } + }, + ); + } + emit(DateSelectedState()); + } + + List energyDataList = []; + void _filterRecordsByDate( + FilterRecordsByDateEvent event, Emitter emit) { + print('dddddddddddddddddddd'); + // emit(SmartPowerLoading()); + if (event.viewType == 'Year') { + filteredRecords = record + .where((record) => record.eventTime!.year == event.selectedDate.year) + .toList(); + } else if (event.viewType == 'Month') { + filteredRecords = record + .where((record) => + record.eventTime!.year == event.selectedDate.year && + record.eventTime!.month == event.selectedDate.month) + .toList(); + } else if (event.viewType == 'Day') { + filteredRecords = record + .where((record) => + record.eventTime!.year == event.selectedDate.year && + record.eventTime!.month == event.selectedDate.month && + record.eventTime!.day == event.selectedDate.day) + .toList(); + } + String getMonthShortName(int month) { + final date = DateTime(0, month); + return DateFormat.MMM().format(date); + } + + energyDataList = filteredRecords.map((eventDevice) { + return EnergyData( + event.viewType == 'Year' + ? getMonthShortName( + int.tryParse(DateFormat('MM').format(eventDevice.eventTime!))!) + : event.viewType == 'Month' + ? DateFormat('yyyy/MM/dd').format(eventDevice.eventTime!) + : DateFormat('HH:mm:ss').format(eventDevice.eventTime!), + double.parse(eventDevice.value!), + ); + }).toList(); + + Future.delayed(const Duration(milliseconds: 500)); + emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + + emit(FilterRecordsState(filteredRecords: energyDataList)); + } } 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 9eb680cd..0e18cbb9 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 @@ -1,4 +1,5 @@ import 'package:equatable/equatable.dart'; +import 'package:flutter/material.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart'; class SmartPowerEvent extends Equatable { @@ -57,6 +58,7 @@ class WallLightFactoryReset extends SmartPowerEvent { @override List get props => [deviceId, factoryReset]; } + class PageChangedEvent extends SmartPowerEvent { final int newPage; PageChangedEvent(this.newPage); @@ -65,4 +67,27 @@ class PageChangedEvent extends SmartPowerEvent { class PageArrowPressedEvent extends SmartPowerEvent { final int direction; PageArrowPressedEvent(this.direction); -} \ No newline at end of file +} + +class SmartPowerArrowPressedEvent extends SmartPowerEvent { + final int direction; + SmartPowerArrowPressedEvent(this.direction); +} + +class SmartPowerPageChangedEvent extends SmartPowerEvent { + final int page; + SmartPowerPageChangedEvent(this.page); +} + +class SelectDateEvent extends SmartPowerEvent { + BuildContext context; + SelectDateEvent({required this.context}); +} + +class FilterRecordsByDateEvent extends SmartPowerEvent { + final DateTime selectedDate; + final String viewType; // 'Day', 'Month', 'Year' + + FilterRecordsByDateEvent( + {required this.selectedDate, required this.viewType}); +} 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 7d705a72..ad75872e 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 @@ -1,5 +1,6 @@ import 'package:equatable/equatable.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_chart.dart'; class SmartPowerState extends Equatable { @override @@ -9,16 +10,15 @@ class SmartPowerState extends Equatable { class SmartPowerInitial extends SmartPowerState {} class SmartPowerLoading extends SmartPowerState {} +class DateSelectedState extends SmartPowerState {} class SmartPowerStatusLoaded extends SmartPowerState { - final PowerClampModel status; - - SmartPowerStatusLoaded(this.status); - - @override - List get props => [status]; + final PowerClampModel deviceStatus; + final int currentPage; + SmartPowerStatusLoaded(this.deviceStatus, this.currentPage); } + class SmartPowerError extends SmartPowerState { final String message; @@ -55,3 +55,8 @@ class SmartPowerBatchStatusLoaded extends SmartPowerState { List get props => [status]; } +class FilterRecordsState extends SmartPowerState { + final List filteredRecords; + + FilterRecordsState({required this.filteredRecords}); +} diff --git a/lib/pages/device_managment/power_clamp/models/device_event.dart b/lib/pages/device_managment/power_clamp/models/device_event.dart new file mode 100644 index 00000000..09f7b46e --- /dev/null +++ b/lib/pages/device_managment/power_clamp/models/device_event.dart @@ -0,0 +1,23 @@ + +class EventDevice { + final String? code; + final DateTime? eventTime; + final String? value; + + EventDevice({ + this.code, + this.eventTime, + this.value, + }); + + EventDevice.fromJson(Map json) + : code = json['code'] as String?, + eventTime = json['eventTime'] , + value = json['value'] as String?; + + Map toJson() => { + 'code': code, + 'eventTime': eventTime, + 'value': value, + }; +} 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 28e91cd5..a4cb4a07 100644 --- a/lib/pages/device_managment/power_clamp/view/power_chart.dart +++ b/lib/pages/device_managment/power_clamp/view/power_chart.dart @@ -6,11 +6,17 @@ class EnergyConsumptionPage extends StatefulWidget { final List chartData; final double totalConsumption; final String date; + final String formattedDate; + final Widget widget; + final Function()? onTap; EnergyConsumptionPage({ required this.chartData, required this.totalConsumption, required this.date, + required this.widget, + required this.onTap, + required this.formattedDate, }); @override @@ -85,135 +91,186 @@ class _EnergyConsumptionPageState extends State { ], ), Expanded( - child: Padding( - padding: const EdgeInsets.only(top: 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: 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, - ), + 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; + }, + 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(); + }, + ), + ), + ), + 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, ); - }).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)), - ), + }, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.withOpacity(0.2), + dashArray: [5, 5], + strokeWidth: 1, ); - } - 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, - 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, + }, + 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, + 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, + ), + ), + dotData: FlDotData( + show: false, + ), + isStrokeCapRound: true, + barWidth: 2, + ), + ], + borderData: FlBorderData( + show: false, + border: Border.all( + color: Color(0xff023DFE).withOpacity(0.7), + width: 10, + ), ), ), - dotData: 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)), + ), + ), + 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), + ), + )), + ), + ), + ), + ), + ], + ), + ) + ], ), ), ], 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 884a668a..531a4297 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 @@ -12,23 +12,17 @@ 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 StatefulWidget +class SmartPowerDeviceControl extends StatelessWidget 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 BlocProvider( - create: (context) => SmartPowerBloc(deviceId: widget.deviceId) - ..add(SmartPowerFetchDeviceEvent(widget.deviceId)), + create: (context) => SmartPowerBloc(deviceId: deviceId) + ..add(SmartPowerFetchDeviceEvent(deviceId)), child: BlocBuilder( builder: (context, state) { final _blocProvider = BlocProvider.of(context); @@ -37,6 +31,7 @@ class _SmartPowerDeviceControlState extends State { return const Center(child: CircularProgressIndicator()); } else if (state is SmartPowerStatusLoaded) { return _buildStatusControls( + currentPage: _blocProvider.currentPage, context: context, blocProvider: _blocProvider, ); @@ -51,24 +46,9 @@ class _SmartPowerDeviceControlState extends State { Widget _buildStatusControls({ required BuildContext context, required SmartPowerBloc blocProvider, + required int currentPage, }) { - 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, - ); - }); - } - + PageController _pageController = PageController(initialPage: currentPage); return Container( child: DeviceControlsContainer( child: Column( @@ -84,45 +64,55 @@ class _SmartPowerDeviceControlState extends State { ), ], ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - PowerClampInfoCard( - iconPath: Assets.powerActiveIcon, - title: 'Active', - value: blocProvider - .deviceStatus.status.general.dataPoints[2].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[4].value - .toString(), - unit: ' Hz', - ), - ], + Padding( + padding: const EdgeInsets.all(10.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + PowerClampInfoCard( + iconPath: Assets.powerActiveIcon, + title: 'Active', + value: blocProvider + .deviceStatus.status.general.dataPoints[2].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[4].value + .toString(), + unit: ' Hz', + ), + ], + ), + ), + SizedBox( + height: 10, ), PhaseWidget( phaseData: blocProvider.phaseData, ), Container( - padding: EdgeInsets.all(10), + padding: EdgeInsets.only( + top: 10, + left: 20, + right: 20, + ), decoration: BoxDecoration( color: ColorsManager.whiteColors, borderRadius: BorderRadius.circular(20), ), - height: 250, + height: 325, child: Column( children: [ Container( @@ -130,94 +120,125 @@ class _SmartPowerDeviceControlState extends State { color: ColorsManager.graysColor, borderRadius: BorderRadius.circular(20), ), - height: 60, + height: 50, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ IconButton( - icon: Icon(Icons.arrow_left), - onPressed: () => _onArrowPressed(-1), + icon: const Icon(Icons.arrow_left), + onPressed: () { + blocProvider.add(SmartPowerArrowPressedEvent(-1)); + _pageController.previousPage( + duration: Duration(milliseconds: 300), + curve: Curves.easeInOut, + ); + }, ), Text( - _currentPage == 0 + currentPage == 0 ? 'Total' - : _currentPage == 0 + : currentPage == 1 ? 'Phase A' - : _currentPage == 0 + : currentPage == 2 ? 'Phase B' : 'Phase C', style: TextStyle(fontSize: 18), ), IconButton( icon: Icon(Icons.arrow_right), - onPressed: () => _onArrowPressed(1), + onPressed: () { + blocProvider.add(SmartPowerArrowPressedEvent(1)); + _pageController.nextPage( + duration: Duration(milliseconds: 300), + curve: Curves.easeInOut, + ); + }, ), ], ), ), + SizedBox( + height: 10, + ), Expanded( child: PageView( controller: _pageController, onPageChanged: (int page) { - setState(() { - _currentPage = page; - }); + blocProvider.add(SmartPowerPageChangedEvent(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), - ], + formattedDate: blocProvider.formattedDate, + onTap: () { + blocProvider.add(SelectDateEvent(context: context)); + }, + widget: blocProvider.dateSwitcher(), + chartData: blocProvider.energyDataList.isNotEmpty + ? blocProvider.energyDataList + : [ + 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', ), 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), - ], + formattedDate: blocProvider.formattedDate, + onTap: () { + blocProvider.add(SelectDateEvent(context: context)); + }, + widget: blocProvider.dateSwitcher(), + chartData: blocProvider.energyDataList.isNotEmpty + ? blocProvider.energyDataList + : [ + 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', ), 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), - ], + formattedDate: blocProvider.formattedDate, + onTap: () { + blocProvider.add(SelectDateEvent(context: context)); + }, + widget: blocProvider.dateSwitcher(), + chartData: blocProvider.energyDataList.isNotEmpty + ? blocProvider.energyDataList + : [ + 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('11:00 AM', 6.0), + ], totalConsumption: 10000, date: '10/08/2024', ), From b8ad20b3ffc04e66d96d810aaa12e52a6a3583bc Mon Sep 17 00:00:00 2001 From: mohammad Date: Thu, 24 Oct 2024 17:40:32 +0300 Subject: [PATCH 12/26] power_clamp_functionality --- .../power_clamp/bloc/smart_power_bloc.dart | 160 ++++++++++++------ .../power_clamp/view/power_chart.dart | 8 +- .../view/smart_power_device_control.dart | 11 ++ 3 files changed, 122 insertions(+), 57 deletions(-) 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 d36f0c74..02cf620d 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 @@ -522,7 +522,7 @@ class SmartPowerBloc extends Bloc { Future dayMonthYearPicker({ required BuildContext context, }) async { - DateTime selectedDate = DateTime.now(); // Default selected date + DateTime selectedDate = DateTime.now(); return await showDialog( context: context, @@ -584,61 +584,107 @@ class SmartPowerBloc extends Bloc { DateTime? dateTime = DateTime.now(); String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now()); + // void checkDayMonthYearSelected( + // SelectDateEvent event, Emitter emit) async { + // if (currentIndex == 0) { + // await dayMonthYearPicker(context: event.context).then( + // (newDate) { + // if (newDate != null) { + // dateTime = newDate; + // formattedDate = DateFormat('yyyy/MM/dd').format(dateTime!); + + // add(FilterRecordsByDateEvent( + // selectedDate: dateTime!, + // viewType: views[currentIndex], + // )); + // } + // }, + // ); + // } else if (currentIndex == 1) { + // await selectMonthAndYear(event.context).then( + // (newDate) { + // if (newDate != null) { + // dateTime = newDate; + // formattedDate = DateFormat('yyyy-MM').format(dateTime!); + + // add(FilterRecordsByDateEvent( + // selectedDate: dateTime!, + // viewType: views[currentIndex], + // )); + // } + // }, + // ); + // } else if (currentIndex == 2) { + // await selectYear(event.context).then( + // (newDate) { + // if (newDate != null) { + // dateTime = newDate; + // formattedDate = DateFormat('yyyy').format(dateTime!); + + // add(FilterRecordsByDateEvent( + // selectedDate: dateTime!, + // viewType: views[currentIndex], + // )); + // } + // }, + // ); + // } + // emit(DateSelectedState()); + // } + void checkDayMonthYearSelected( SelectDateEvent event, Emitter emit) async { - // emit(SmartPowerLoading()); + Future Function(BuildContext context)? dateSelector; + String dateFormat; - if (currentIndex == 0) { - await dayMonthYearPicker(context: event.context).then( - (newDate) { - if (newDate != null) { - dateTime = newDate; - formattedDate = DateFormat('yyyy/MM/dd').format(dateTime!); - - add(FilterRecordsByDateEvent( - selectedDate: dateTime!, - viewType: views[currentIndex], - )); - } - }, - ); - } else if (currentIndex == 1) { - await selectMonthAndYear(event.context).then( - (newDate) { - if (newDate != null) { - dateTime = newDate; - formattedDate = DateFormat('yyyy-MM').format(dateTime!); - - add(FilterRecordsByDateEvent( - selectedDate: dateTime!, - viewType: views[currentIndex], - )); - } - }, - ); - } else if (currentIndex == 2) { - await selectYear(event.context).then( - (newDate) { - if (newDate != null) { - dateTime = newDate; - formattedDate = DateFormat('yyyy').format(dateTime!); - - add(FilterRecordsByDateEvent( - selectedDate: dateTime!, - viewType: views[currentIndex], - )); - } - }, - ); + // Determine which picker to use and format to apply + switch (currentIndex) { + case 0: + dateSelector = (context) { + return dayMonthYearPicker(context: context); + }; + dateFormat = 'yyyy/MM/dd'; + break; + case 1: + dateSelector = (context) { + return selectMonthAndYear(context); + }; + dateFormat = 'yyyy-MM'; + break; + case 2: + dateSelector = (context) { + return selectYear(context); + }; + dateFormat = 'yyyy'; + break; + default: + return; } - emit(DateSelectedState()); + Future.delayed(const Duration(milliseconds: 500), () { + emit(SmartPowerLoading()); + }); + // Use the selected picker + + await dateSelector(event.context).then((newDate) { + add(FilterRecordsByDateEvent( + selectedDate: dateTime!, + viewType: views[currentIndex], + )); + }); + emit(FilterRecordsState(filteredRecords: energyDataList)); + + // emit(DateSelectedState()); } List energyDataList = []; void _filterRecordsByDate( FilterRecordsByDateEvent event, Emitter emit) { - print('dddddddddddddddddddd'); - // emit(SmartPowerLoading()); + emit(SmartPowerLoading()); + + print('FilterRecordsByDate method called'); + print('Selected date: ${event.selectedDate}'); + print('View type: ${event.viewType}'); + if (event.viewType == 'Year') { filteredRecords = record .where((record) => record.eventTime!.year == event.selectedDate.year) @@ -657,11 +703,10 @@ class SmartPowerBloc extends Bloc { record.eventTime!.day == event.selectedDate.day) .toList(); } - String getMonthShortName(int month) { - final date = DateTime(0, month); - return DateFormat.MMM().format(date); - } + print('Filtered Records: ${filteredRecords.length} items found.'); + + // Update `energyDataList` with filtered records. energyDataList = filteredRecords.map((eventDevice) { return EnergyData( event.viewType == 'Year' @@ -674,9 +719,18 @@ class SmartPowerBloc extends Bloc { ); }).toList(); - Future.delayed(const Duration(milliseconds: 500)); - emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + // 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)); } + + String getMonthShortName(int month) { + final date = DateTime(0, month); + return DateFormat.MMM().format(date); + } } 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 a4cb4a07..ce7d6add 100644 --- a/lib/pages/device_managment/power_clamp/view/power_chart.dart +++ b/lib/pages/device_managment/power_clamp/view/power_chart.dart @@ -69,18 +69,18 @@ class _EnergyConsumptionPageState extends State { ), ], ), - const Row( + Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - '01/08/2024 - 31/08/2024', - style: TextStyle( + widget.formattedDate, + style: const TextStyle( color: ColorsManager.grayColor, fontWeight: FontWeight.w400, fontSize: 8, ), ), - Text( + const Text( '1000.00 kWh', style: TextStyle( color: ColorsManager.grayColor, 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 531a4297..dd176c11 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 @@ -35,6 +35,13 @@ class SmartPowerDeviceControl extends StatelessWidget context: context, blocProvider: _blocProvider, ); + } else if (state is FilterRecordsState) { + // Handle the state when the records are filtered + return _buildStatusControls( + currentPage: _blocProvider.currentPage, + context: context, + blocProvider: _blocProvider, + ); } return const Center(child: CircularProgressIndicator()); // } @@ -171,6 +178,10 @@ class SmartPowerDeviceControl extends StatelessWidget formattedDate: blocProvider.formattedDate, onTap: () { blocProvider.add(SelectDateEvent(context: context)); + blocProvider.add(FilterRecordsByDateEvent( + selectedDate: blocProvider.dateTime!, + viewType: blocProvider + .views[blocProvider.currentIndex])); }, widget: blocProvider.dateSwitcher(), chartData: blocProvider.energyDataList.isNotEmpty From a594d5b93cd57195f9135f85687afa0c6faf2623 Mon Sep 17 00:00:00 2001 From: mohammad Date: Fri, 25 Oct 2024 20:06:07 +0300 Subject: [PATCH 13/26] power_clamp_batch_control --- .../helper/route_controls_based_code.dart | 3 +- .../power_clamp/bloc/smart_power_bloc.dart | 111 ++++++++++++++++-- .../power_clamp/bloc/smart_power_event.dart | 26 +++- .../power_clamp/bloc/smart_power_state.dart | 14 ++- .../models/power_clamp_batch_model.dart | 49 ++++++++ .../power_clamp/models/power_clamp_model.dart | 12 ++ .../view/power_clamp_batch_control_view.dart | 67 +++++++++++ .../view/smart_power_device_control.dart | 2 +- lib/services/devices_mang_api.dart | 25 ++++ 9 files changed, 294 insertions(+), 15 deletions(-) create mode 100644 lib/pages/device_managment/power_clamp/models/power_clamp_batch_model.dart create mode 100644 lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart diff --git a/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart b/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart index 6e506a8e..8edb0a1e 100644 --- a/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart +++ b/lib/pages/device_managment/all_devices/helper/route_controls_based_code.dart @@ -18,6 +18,7 @@ import 'package:syncrow_web/pages/device_managment/main_door_sensor/view/main_do import 'package:syncrow_web/pages/device_managment/one_g_glass_switch/view/one_gang_glass_batch_control_view.dart'; import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_batch_control.dart'; import 'package:syncrow_web/pages/device_managment/one_gang_switch/view/wall_light_device_control.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/view/smart_power_device_control.dart'; import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/view/three_gang_glass_switch_batch_control_view.dart'; import 'package:syncrow_web/pages/device_managment/three_g_glass_switch/view/three_gang_glass_switch_control_view.dart'; @@ -230,7 +231,7 @@ mixin RouteControlsBasedCode { .toList(), ); case 'PC': - return WaterLeakBatchControlView( + return PowerClampBatchControlView( deviceIds: devices .where((e) => (e.productType == 'PC')) .map((e) => e.uuid!) 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 02cf620d..4f1bfc62 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,11 +1,14 @@ import 'dart:async'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:intl/intl.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/device_event.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_batch_model.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_chart.dart'; import 'package:syncrow_web/services/devices_mang_api.dart'; @@ -16,13 +19,15 @@ class SmartPowerBloc extends Bloc { on(_onArrowPressed); on(_onFetchBatchStatus); on(_onPageChanged); - on(_onBatchControl); + on(_onBatchControl); on(_filterRecordsByDate); on(checkDayMonthYearSelected); - // SelectDateEvent + on(_onFactoryReset); + // FetchPowerClampBatchStatusEvent } late PowerClampModel deviceStatus; + late PowerClampBatchModel deviceBatchStatus; final String deviceId; Timer? _timer; List> phaseData = []; @@ -255,29 +260,117 @@ class SmartPowerBloc extends Bloc { currentPage = event.page; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); } + + Future _onFactoryReset( + SmartPowerFactoryReset event, Emitter emit) async { + emit(SmartPowerLoading()); + try { + final response = await DevicesManagementApi().factoryReset( + event.factoryReset, + event.deviceId, + ); + if (response) { + emit(SmartPowerInitial()); + } else { + emit(SmartPowerError('Factory reset failed')); + } + } catch (e) { + emit(SmartPowerError(e.toString())); + } + } + + Future _onBatchControl( + PowerBatchControlEvent event, Emitter emit) async { + final oldValue = deviceStatus.status; + + _updateLocalValue(event.code, event.value); + // emit(WaterLeakBatchStatusLoadedState(deviceStatus!)); + + await _runDebounce( + deviceId: event.deviceIds, + code: event.code, + value: event.value, + oldValue: oldValue, + emit: emit, + isBatch: true, + ); + } Future _onFetchBatchStatus( SmartPowerFetchBatchEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - await DevicesManagementApi().getBatchStatus(event.devicesIds); - emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); + final response = + await DevicesManagementApi().getPowerStatus(event.devicesIds); + PowerClampBatchModel deviceStatus = + PowerClampBatchModel.fromJson(response); + + emit(SmartPowerLoadBatchControll(deviceStatus)); } catch (e) { + debugPrint('=========error====$e'); emit(SmartPowerError(e.toString())); } } + Future _runDebounce({ + required dynamic deviceId, + required String code, + required dynamic value, + required dynamic 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 _updateLocalValue(String code, dynamic value) { + if (code == 'watersensor_state') { + deviceStatus = deviceStatus.copyWith(statusPower: value); + } else if (code == 'battery_percentage') { + deviceStatus = deviceStatus.copyWith(statusPower: value); + } + } + + void _revertValueAndEmit(String deviceId, String code, dynamic oldValue, + Emitter emit) { + _updateLocalValue(code, oldValue); + emit(SmartPowerLoadBatchControll(deviceBatchStatus)); + } + @override Future close() { _timer?.cancel(); return super.close(); } - FutureOr _onBatchControl( - SmartPowerBatchControl event, Emitter emit) async { - emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); - } - List filteredRecords = []; int currentIndex = 0; 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 0e18cbb9..1985c67c 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 @@ -49,11 +49,11 @@ class SmartPowerBatchControl extends SmartPowerEvent { List get props => [devicesIds, code, value]; } -class WallLightFactoryReset extends SmartPowerEvent { +class SmartPowerFactoryReset extends SmartPowerEvent { final String deviceId; final FactoryResetModel factoryReset; - WallLightFactoryReset({required this.deviceId, required this.factoryReset}); + SmartPowerFactoryReset({required this.deviceId, required this.factoryReset}); @override List get props => [deviceId, factoryReset]; @@ -91,3 +91,25 @@ class FilterRecordsByDateEvent extends SmartPowerEvent { FilterRecordsByDateEvent( {required this.selectedDate, required this.viewType}); } + +class FetchPowerClampBatchStatusEvent extends SmartPowerEvent { + final List deviceIds; + + FetchPowerClampBatchStatusEvent(this.deviceIds); + + @override + List get props => [deviceIds]; +}class PowerBatchControlEvent extends SmartPowerEvent { + final List deviceIds; + final String code; + final dynamic value; + + PowerBatchControlEvent({ + required this.deviceIds, + required this.code, + required this.value, + }); + + @override + List get props => [deviceIds, code, value]; +} \ 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 ad75872e..17e79b7e 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 @@ -1,4 +1,5 @@ import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_batch_model.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; import 'package:syncrow_web/pages/device_managment/power_clamp/view/power_chart.dart'; @@ -10,6 +11,16 @@ class SmartPowerState extends Equatable { class SmartPowerInitial extends SmartPowerState {} class SmartPowerLoading extends SmartPowerState {} + +class SmartPowerLoadBatchControll extends SmartPowerState { + final PowerClampBatchModel status; + + SmartPowerLoadBatchControll(this.status); + + @override + List get props => [status]; +} + class DateSelectedState extends SmartPowerState {} class SmartPowerStatusLoaded extends SmartPowerState { @@ -18,7 +29,6 @@ class SmartPowerStatusLoaded extends SmartPowerState { SmartPowerStatusLoaded(this.deviceStatus, this.currentPage); } - class SmartPowerError extends SmartPowerState { final String message; @@ -58,5 +68,5 @@ class SmartPowerBatchStatusLoaded extends SmartPowerState { class FilterRecordsState extends SmartPowerState { final List filteredRecords; - FilterRecordsState({required this.filteredRecords}); + FilterRecordsState({required this.filteredRecords}); } diff --git a/lib/pages/device_managment/power_clamp/models/power_clamp_batch_model.dart b/lib/pages/device_managment/power_clamp/models/power_clamp_batch_model.dart new file mode 100644 index 00000000..1812d1c9 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/models/power_clamp_batch_model.dart @@ -0,0 +1,49 @@ +import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; + +abstract class PowerClampModel1 { + String get productUuid; + String get productType; +} + +class PowerClampBatchModel extends PowerClampModel1 { + @override + final String productUuid; + @override + final String productType; + final List status; + + PowerClampBatchModel({ + required this.productUuid, + required this.productType, + required this.status, + }); + + factory PowerClampBatchModel.fromJson(Map json) { + String productUuid = json['productUuid'] ?? ''; + String productType = json['productType'] ?? ''; + + List statusList = []; + if (json['status'] != null && json['status'] is List) { + statusList = + (json['status'] as List).map((e) => Status.fromJson(e)).toList(); + } + + return PowerClampBatchModel( + productUuid: productUuid, + productType: productType, + status: statusList, + ); + } + + PowerClampBatchModel copyWith({ + String? productUuid, + String? productType, + List? status, + }) { + return PowerClampBatchModel( + productUuid: productUuid ?? this.productUuid, + productType: productType ?? this.productType, + status: status ?? this.status, + ); + } +} diff --git a/lib/pages/device_managment/power_clamp/models/power_clamp_model.dart b/lib/pages/device_managment/power_clamp/models/power_clamp_model.dart index 7fb09d47..914a255b 100644 --- a/lib/pages/device_managment/power_clamp/models/power_clamp_model.dart +++ b/lib/pages/device_managment/power_clamp/models/power_clamp_model.dart @@ -17,6 +17,18 @@ class PowerClampModel { status: PowerStatus.fromJson(json['status']), ); } + + PowerClampModel copyWith({ + String? productUuid, + String? productType, + PowerStatus? statusPower, + }) { + return PowerClampModel( + productUuid: productUuid ?? this.productUuid, + productType: productType ?? this.productType, + status: statusPower ?? this.status, + ); + } } class PowerStatus { diff --git a/lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart b/lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart new file mode 100644 index 00000000..886ae5b1 --- /dev/null +++ b/lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart @@ -0,0 +1,67 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.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/models/power_clamp_batch_model.dart'; +import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; +import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart'; +import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart'; +import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; + +class PowerClampBatchControlView extends StatelessWidget + with HelperResponsiveLayout { + final List deviceIds; + + const PowerClampBatchControlView({Key? key, required this.deviceIds}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return BlocProvider( + create: (context) => SmartPowerBloc(deviceId: deviceIds.first) + ..add(SmartPowerFetchBatchEvent(deviceIds)), + child: BlocBuilder( + builder: (context, state) { + if (state is SmartPowerLoading) { + return const Center(child: CircularProgressIndicator()); + } else if (state is SmartPowerLoadBatchControll) { + return _buildStatusControls(context, state.status); + } else if (state is SmartPowerError) { + return Center(child: Text('Error: ${state.message}')); + } else { + return const Center(child: CircularProgressIndicator()); + } + }, + ), + ); + } + + Widget _buildStatusControls( + BuildContext context, PowerClampBatchModel status) { + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + width: 170, + height: 140, + child: FirmwareUpdateWidget(deviceId: deviceIds.first, version: 2)), + const SizedBox( + width: 12, + ), + SizedBox( + width: 170, + height: 140, + child: FactoryResetWidget( + callFactoryReset: () { + context.read().add(SmartPowerFactoryReset( + deviceId: deviceIds.first, + factoryReset: FactoryResetModel(devicesUuid: deviceIds))); + }, + ), + ), + ], + ); + } +} 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 dd176c11..82c28ddf 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,7 +29,7 @@ class SmartPowerDeviceControl extends StatelessWidget if (state is SmartPowerLoading) { return const Center(child: CircularProgressIndicator()); - } else if (state is SmartPowerStatusLoaded) { + } else if (state is SmartPowerLoadBatchControll) { return _buildStatusControls( currentPage: _blocProvider.currentPage, context: context, diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index 4abb606f..82a06b18 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -195,6 +195,31 @@ class DevicesManagementApi { } } + getPowerStatus(List uuids) async { + try { + final queryParameters = { + 'devicesUuid': uuids.join(','), + }; + final response = await HTTPService().get( + path: ApiEndpoints.getBatchStatus, + queryParameters: queryParameters, + showServerMessage: true, + expectedResponseModel: (json) { + print('object======$json'); + return json; + }, + ); + return response; + } catch (e) { + debugPrint('Error fetching $e'); + return DeviceStatus( + productUuid: '', + productType: '', + status: [], + ); + } + } + Future addScheduleRecord( ScheduleEntry sendSchedule, String uuid) async { try { From 23e54c7e78499aec7fec4bfa7bf7b4820061717d Mon Sep 17 00:00:00 2001 From: mohammad Date: Fri, 25 Oct 2024 20:17:34 +0300 Subject: [PATCH 14/26] batch_control --- .../power_clamp/bloc/smart_power_bloc.dart | 55 +------------------ 1 file changed, 3 insertions(+), 52 deletions(-) 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 4f1bfc62..6d4033fa 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 @@ -260,7 +260,7 @@ class SmartPowerBloc extends Bloc { currentPage = event.page; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); } - + Future _onFactoryReset( SmartPowerFactoryReset event, Emitter emit) async { emit(SmartPowerLoading()); @@ -588,16 +588,14 @@ 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 }, ), ], @@ -677,53 +675,6 @@ class SmartPowerBloc extends Bloc { DateTime? dateTime = DateTime.now(); String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now()); - // void checkDayMonthYearSelected( - // SelectDateEvent event, Emitter emit) async { - // if (currentIndex == 0) { - // await dayMonthYearPicker(context: event.context).then( - // (newDate) { - // if (newDate != null) { - // dateTime = newDate; - // formattedDate = DateFormat('yyyy/MM/dd').format(dateTime!); - - // add(FilterRecordsByDateEvent( - // selectedDate: dateTime!, - // viewType: views[currentIndex], - // )); - // } - // }, - // ); - // } else if (currentIndex == 1) { - // await selectMonthAndYear(event.context).then( - // (newDate) { - // if (newDate != null) { - // dateTime = newDate; - // formattedDate = DateFormat('yyyy-MM').format(dateTime!); - - // add(FilterRecordsByDateEvent( - // selectedDate: dateTime!, - // viewType: views[currentIndex], - // )); - // } - // }, - // ); - // } else if (currentIndex == 2) { - // await selectYear(event.context).then( - // (newDate) { - // if (newDate != null) { - // dateTime = newDate; - // formattedDate = DateFormat('yyyy').format(dateTime!); - - // add(FilterRecordsByDateEvent( - // selectedDate: dateTime!, - // viewType: views[currentIndex], - // )); - // } - // }, - // ); - // } - // emit(DateSelectedState()); - // } void checkDayMonthYearSelected( SelectDateEvent event, Emitter emit) async { From b7dddcb8dd18e559c24c604aec59ac2fc905888c Mon Sep 17 00:00:00 2001 From: mohammad Date: Sun, 27 Oct 2024 12:36:32 +0300 Subject: [PATCH 15/26] shadow and text color --- .../access_management/bloc/access_bloc.dart | 158 ++++++++++++------ .../view/access_management.dart | 64 +++---- lib/pages/common/date_time_widget.dart | 5 +- .../common/text_field/custom_text_field.dart | 30 ++-- .../text_field/custom_web_textfield.dart | 30 ++-- .../widgets/device_managment_body.dart | 51 ++++-- .../widgets/device_search_filters.dart | 36 ++-- lib/utils/color_manager.dart | 2 +- lib/utils/style.dart | 9 +- pubspec.lock | 24 +-- 10 files changed, 255 insertions(+), 154 deletions(-) diff --git a/lib/pages/access_management/bloc/access_bloc.dart b/lib/pages/access_management/bloc/access_bloc.dart index 55b525b4..3e74dbff 100644 --- a/lib/pages/access_management/bloc/access_bloc.dart +++ b/lib/pages/access_management/bloc/access_bloc.dart @@ -5,6 +5,7 @@ import 'package:syncrow_web/pages/access_management/bloc/access_state.dart'; import 'package:syncrow_web/pages/access_management/model/password_model.dart'; import 'package:syncrow_web/pages/common/hour_picker_dialog.dart'; import 'package:syncrow_web/services/access_mang_api.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/app_enum.dart'; import 'package:syncrow_web/utils/snack_bar.dart'; @@ -26,7 +27,8 @@ class AccessBloc extends Bloc { List filteredData = []; List data = []; - Future _onFetchTableData(FetchTableData event, Emitter emit) async { + Future _onFetchTableData( + FetchTableData event, Emitter emit) async { try { emit(AccessLoaded()); data = await AccessMangApi().fetchVisitorPassword(); @@ -39,19 +41,28 @@ class AccessBloc extends Bloc { } void updateTabsCount() { - int toBeEffectiveCount = - data.where((item) => item.passwordStatus.value == 'To be effective').length; - int effectiveCount = data.where((item) => item.passwordStatus.value == 'Effective').length; - int expiredCount = data.where((item) => item.passwordStatus.value == 'Expired').length; + int toBeEffectiveCount = data + .where((item) => item.passwordStatus.value == 'To be effective') + .length; + int effectiveCount = + data.where((item) => item.passwordStatus.value == 'Effective').length; + int expiredCount = + data.where((item) => item.passwordStatus.value == 'Expired').length; tabs[1] = 'To Be Effective ($toBeEffectiveCount)'; tabs[2] = 'Effective ($effectiveCount)'; tabs[3] = 'Expired ($expiredCount)'; } int selectedIndex = 0; - final List tabs = ['All', 'To Be Effective (0)', 'Effective (0)', 'Expired']; + final List tabs = [ + 'All', + 'To Be Effective (0)', + 'Effective (0)', + 'Expired' + ]; - Future selectFilterTap(TabChangedEvent event, Emitter emit) async { + Future selectFilterTap( + TabChangedEvent event, Emitter emit) async { try { emit(AccessLoaded()); selectedIndex = event.selectedIndex; @@ -73,6 +84,23 @@ class AccessBloc extends Bloc { initialDate: DateTime.now(), firstDate: DateTime.now().add(const Duration(days: -5095)), lastDate: DateTime.now().add(const Duration(days: 2095)), + builder: (BuildContext context, Widget? child) { + return Theme( + data: ThemeData.light().copyWith( + colorScheme: ColorScheme.light( + primary: ColorsManager.blackColor, + onPrimary: Colors.white, + onSurface: ColorsManager.grayColor, + ), + textButtonTheme: TextButtonThemeData( + style: TextButton.styleFrom( + foregroundColor: Colors.blue, + ), + ), + ), + child: child!, + ); + }, ); if (picked != null) { final TimeOfDay? timePicked = await showHourPicker( @@ -88,16 +116,20 @@ class AccessBloc extends Bloc { timePicked.hour, timePicked.minute, ); - final int selectedTimestamp = selectedDateTime.millisecondsSinceEpoch ~/ 1000; + final int selectedTimestamp = + selectedDateTime.millisecondsSinceEpoch ~/ 1000; if (event.isStart) { - if (expirationTimeTimeStamp != null && selectedTimestamp > expirationTimeTimeStamp!) { - CustomSnackBar.displaySnackBar('Effective Time cannot be later than Expiration Time.'); + if (expirationTimeTimeStamp != null && + selectedTimestamp > expirationTimeTimeStamp!) { + CustomSnackBar.displaySnackBar( + 'Effective Time cannot be later than Expiration Time.'); } else { startTime = selectedDateTime.toString().split('.').first; effectiveTimeTimeStamp = selectedTimestamp; } } else { - if (effectiveTimeTimeStamp != null && selectedTimestamp < effectiveTimeTimeStamp!) { + if (effectiveTimeTimeStamp != null && + selectedTimestamp < effectiveTimeTimeStamp!) { CustomSnackBar.displaySnackBar( 'Expiration Time cannot be earlier than Effective Time.'); } else { @@ -110,7 +142,8 @@ class AccessBloc extends Bloc { emit(ChangeTimeState()); } - Future _filterData(FilterDataEvent event, Emitter emit) async { + Future _filterData( + FilterDataEvent event, Emitter emit) async { emit(AccessLoaded()); try { // Convert search text to lower case for case-insensitive search @@ -119,29 +152,40 @@ class AccessBloc extends Bloc { filteredData = data.where((item) { bool matchesCriteria = true; // Convert timestamp to DateTime and extract date component - DateTime effectiveDate = - DateTime.fromMillisecondsSinceEpoch(int.parse(item.effectiveTime.toString()) * 1000) - .toUtc() - .toLocal(); - DateTime invalidDate = - DateTime.fromMillisecondsSinceEpoch(int.parse(item.invalidTime.toString()) * 1000) - .toUtc() - .toLocal(); - DateTime effectiveDateAndTime = DateTime(effectiveDate.year, effectiveDate.month, - effectiveDate.day, effectiveDate.hour, effectiveDate.minute); - DateTime invalidDateAndTime = DateTime(invalidDate.year, invalidDate.month, invalidDate.day, - invalidDate.hour, invalidDate.minute); + DateTime effectiveDate = DateTime.fromMillisecondsSinceEpoch( + int.parse(item.effectiveTime.toString()) * 1000) + .toUtc() + .toLocal(); + DateTime invalidDate = DateTime.fromMillisecondsSinceEpoch( + int.parse(item.invalidTime.toString()) * 1000) + .toUtc() + .toLocal(); + DateTime effectiveDateAndTime = DateTime( + effectiveDate.year, + effectiveDate.month, + effectiveDate.day, + effectiveDate.hour, + effectiveDate.minute); + DateTime invalidDateAndTime = DateTime( + invalidDate.year, + invalidDate.month, + invalidDate.day, + invalidDate.hour, + invalidDate.minute); // Filter by password name, making the search case-insensitive if (searchText.isNotEmpty) { - final bool matchesName = item.passwordName.toString().toLowerCase().contains(searchText); + final bool matchesName = + item.passwordName.toString().toLowerCase().contains(searchText); if (!matchesName) { matchesCriteria = false; } } if (searchEmailText.isNotEmpty) { - final bool matchesName = - item.authorizerEmail.toString().toLowerCase().contains(searchEmailText); + final bool matchesName = item.authorizerEmail + .toString() + .toLowerCase() + .contains(searchEmailText); if (!matchesName) { matchesCriteria = false; } @@ -149,9 +193,11 @@ class AccessBloc extends Bloc { // Filter by start date only if (event.startTime != null && event.endTime == null) { DateTime startDateTime = - DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal(); - startDateTime = DateTime(startDateTime.year, startDateTime.month, startDateTime.day, - startDateTime.hour, startDateTime.minute); + DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000) + .toUtc() + .toLocal(); + startDateTime = DateTime(startDateTime.year, startDateTime.month, + startDateTime.day, startDateTime.hour, startDateTime.minute); if (effectiveDateAndTime.isBefore(startDateTime)) { matchesCriteria = false; } @@ -159,9 +205,11 @@ class AccessBloc extends Bloc { // Filter by end date only if (event.endTime != null && event.startTime == null) { DateTime startDateTime = - DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal(); - startDateTime = DateTime(startDateTime.year, startDateTime.month, startDateTime.day, - startDateTime.hour, startDateTime.minute); + DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000) + .toUtc() + .toLocal(); + startDateTime = DateTime(startDateTime.year, startDateTime.month, + startDateTime.day, startDateTime.hour, startDateTime.minute); if (invalidDateAndTime.isAfter(startDateTime)) { matchesCriteria = false; } @@ -170,13 +218,17 @@ class AccessBloc extends Bloc { // Filter by both start date and end date if (event.startTime != null && event.endTime != null) { DateTime startDateTime = - DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000).toUtc().toLocal(); + DateTime.fromMillisecondsSinceEpoch(event.startTime! * 1000) + .toUtc() + .toLocal(); DateTime endDateTime = - DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000).toUtc().toLocal(); - startDateTime = DateTime(startDateTime.year, startDateTime.month, startDateTime.day, - startDateTime.hour, startDateTime.minute); - endDateTime = DateTime(endDateTime.year, endDateTime.month, endDateTime.day, - endDateTime.hour, endDateTime.minute); + DateTime.fromMillisecondsSinceEpoch(event.endTime! * 1000) + .toUtc() + .toLocal(); + startDateTime = DateTime(startDateTime.year, startDateTime.month, + startDateTime.day, startDateTime.hour, startDateTime.minute); + endDateTime = DateTime(endDateTime.year, endDateTime.month, + endDateTime.day, endDateTime.hour, endDateTime.minute); if (effectiveDateAndTime.isBefore(startDateTime) || invalidDateAndTime.isAfter(endDateTime)) { matchesCriteria = false; @@ -184,11 +236,14 @@ class AccessBloc extends Bloc { } // Filter by selected tab index - if (event.selectedTabIndex == 1 && item.passwordStatus.value != 'To be effective') { + if (event.selectedTabIndex == 1 && + item.passwordStatus.value != 'To be effective') { matchesCriteria = false; - } else if (event.selectedTabIndex == 2 && item.passwordStatus.value != 'Effective') { + } else if (event.selectedTabIndex == 2 && + item.passwordStatus.value != 'Effective') { matchesCriteria = false; - } else if (event.selectedTabIndex == 3 && item.passwordStatus.value != 'Expired') { + } else if (event.selectedTabIndex == 3 && + item.passwordStatus.value != 'Expired') { matchesCriteria = false; } @@ -214,12 +269,14 @@ class AccessBloc extends Bloc { } String timestampToDate(dynamic timestamp) { - DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(int.parse(timestamp) * 1000); + DateTime dateTime = + DateTime.fromMillisecondsSinceEpoch(int.parse(timestamp) * 1000); return "${dateTime.year}/${dateTime.month.toString().padLeft(2, '0')}/${dateTime.day.toString().padLeft(2, '0')} " " ${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}"; } - Future onTabChanged(TabChangedEvent event, Emitter emit) async { + Future onTabChanged( + TabChangedEvent event, Emitter emit) async { try { emit(AccessLoaded()); selectedIndex = event.selectedIndex; @@ -228,14 +285,19 @@ class AccessBloc extends Bloc { filteredData = data; break; case 1: // To Be Effective - filteredData = - data.where((item) => item.passwordStatus.value == "To Be Effective").toList(); + filteredData = data + .where((item) => item.passwordStatus.value == "To Be Effective") + .toList(); break; case 2: // Effective - filteredData = data.where((item) => item.passwordStatus.value == "Effective").toList(); + filteredData = data + .where((item) => item.passwordStatus.value == "Effective") + .toList(); break; case 3: // Expired - filteredData = data.where((item) => item.passwordStatus.value == "Expired").toList(); + filteredData = data + .where((item) => item.passwordStatus.value == "Expired") + .toList(); break; default: filteredData = data; diff --git a/lib/pages/access_management/view/access_management.dart b/lib/pages/access_management/view/access_management.dart index caa5fe28..bed27eea 100644 --- a/lib/pages/access_management/view/access_management.dart +++ b/lib/pages/access_management/view/access_management.dart @@ -27,7 +27,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { final isLargeScreen = isLargeScreenSize(context); final isSmallScreen = isSmallScreenSize(context); final isHalfMediumScreen = isHafMediumScreenSize(context); - final padding = isLargeScreen ? const EdgeInsets.all(30) : const EdgeInsets.all(15); + final padding = + isLargeScreen ? const EdgeInsets.all(30) : const EdgeInsets.all(15); return WebScaffold( enableMenuSidebar: false, @@ -37,23 +38,10 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { style: Theme.of(context).textTheme.headlineLarge, ), ), - centerBody: Wrap( - children: [ - Padding( - padding: EdgeInsets.only(left: MediaQuery.of(context).size.width * 0.09), - child: Align( - alignment: Alignment.bottomLeft, - child: Text( - 'Physical Access', - style: Theme.of(context).textTheme.headlineMedium!.copyWith(color: Colors.white), - ), - ), - ), - ], - ), rightBody: const NavigateHomeGridView(), scaffoldBody: BlocProvider( - create: (BuildContext context) => AccessBloc()..add(FetchTableData()), + create: (BuildContext context) => + AccessBloc()..add(FetchTableData()), child: BlocConsumer( listener: (context, state) {}, builder: (context, state) { @@ -107,11 +95,14 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { return [ item.passwordName, item.passwordType.value, - accessBloc.timestampToDate(item.effectiveTime), - accessBloc.timestampToDate(item.invalidTime), + accessBloc + .timestampToDate(item.effectiveTime), + accessBloc + .timestampToDate(item.invalidTime), item.deviceName.toString(), item.authorizerEmail.toString(), - accessBloc.timestampToDate(item.invalidTime), + accessBloc + .timestampToDate(item.invalidTime), item.passwordStatus.value, ]; }).toList(), @@ -122,7 +113,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { }))); } - Wrap _buildVisitorAdminPasswords(BuildContext context, AccessBloc accessBloc) { + Wrap _buildVisitorAdminPasswords( + BuildContext context, AccessBloc accessBloc) { return Wrap( spacing: 10, runSpacing: 10, @@ -147,8 +139,9 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { }, borderRadius: 8, child: Text( - '+ Create Visitor Password ', - style: context.textTheme.titleSmall!.copyWith(color: Colors.white, fontSize: 12), + 'Create Visitor Password ', + style: context.textTheme.titleSmall! + .copyWith(color: Colors.white, fontSize: 12), )), ), Container( @@ -160,7 +153,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { backgroundColor: ColorsManager.whiteColors, child: Text( 'Admin Password', - style: context.textTheme.titleSmall!.copyWith(color: Colors.black, fontSize: 12), + style: context.textTheme.titleSmall! + .copyWith(color: Colors.black, fontSize: 12), )), ), ], @@ -185,8 +179,10 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { description: '', onSubmitted: (value) { accessBloc.add(FilterDataEvent( - emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), - selectedTabIndex: BlocProvider.of(context).selectedIndex, + emailAuthorizer: + accessBloc.emailAuthorizer.text.toLowerCase(), + selectedTabIndex: + BlocProvider.of(context).selectedIndex, passwordName: accessBloc.passwordName.text.toLowerCase(), startTime: accessBloc.effectiveTimeTimeStamp, endTime: accessBloc.expirationTimeTimeStamp)); @@ -204,8 +200,10 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { description: '', onSubmitted: (value) { accessBloc.add(FilterDataEvent( - emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), - selectedTabIndex: BlocProvider.of(context).selectedIndex, + emailAuthorizer: + accessBloc.emailAuthorizer.text.toLowerCase(), + selectedTabIndex: + BlocProvider.of(context).selectedIndex, passwordName: accessBloc.passwordName.text.toLowerCase(), startTime: accessBloc.effectiveTimeTimeStamp, endTime: accessBloc.expirationTimeTimeStamp)); @@ -234,7 +232,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { onSearch: () { accessBloc.add(FilterDataEvent( emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), - selectedTabIndex: BlocProvider.of(context).selectedIndex, + selectedTabIndex: + BlocProvider.of(context).selectedIndex, passwordName: accessBloc.passwordName.text.toLowerCase(), startTime: accessBloc.effectiveTimeTimeStamp, endTime: accessBloc.expirationTimeTimeStamp)); @@ -262,8 +261,10 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { description: '', onSubmitted: (value) { accessBloc.add(FilterDataEvent( - emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), - selectedTabIndex: BlocProvider.of(context).selectedIndex, + emailAuthorizer: + accessBloc.emailAuthorizer.text.toLowerCase(), + selectedTabIndex: + BlocProvider.of(context).selectedIndex, passwordName: accessBloc.passwordName.text.toLowerCase(), startTime: accessBloc.effectiveTimeTimeStamp, endTime: accessBloc.expirationTimeTimeStamp)); @@ -287,7 +288,8 @@ class AccessManagementPage extends StatelessWidget with HelperResponsiveLayout { onSearch: () { accessBloc.add(FilterDataEvent( emailAuthorizer: accessBloc.emailAuthorizer.text.toLowerCase(), - selectedTabIndex: BlocProvider.of(context).selectedIndex, + selectedTabIndex: + BlocProvider.of(context).selectedIndex, passwordName: accessBloc.passwordName.text.toLowerCase(), startTime: accessBloc.effectiveTimeTimeStamp, endTime: accessBloc.expirationTimeTimeStamp)); diff --git a/lib/pages/common/date_time_widget.dart b/lib/pages/common/date_time_widget.dart index 0965377e..8dbcc9aa 100644 --- a/lib/pages/common/date_time_widget.dart +++ b/lib/pages/common/date_time_widget.dart @@ -81,7 +81,10 @@ class DateTimeWebWidget extends StatelessWidget { const SizedBox( width: 30, ), - const Icon(Icons.arrow_right_alt), + const Icon( + Icons.arrow_right_alt, + color: ColorsManager.grayColor, + ), const SizedBox( width: 30, ), diff --git a/lib/pages/common/text_field/custom_text_field.dart b/lib/pages/common/text_field/custom_text_field.dart index c85e911d..b695da4a 100644 --- a/lib/pages/common/text_field/custom_text_field.dart +++ b/lib/pages/common/text_field/custom_text_field.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:syncrow_web/utils/extension/build_context_x.dart'; +import 'package:syncrow_web/utils/style.dart'; class StatefulTextField extends StatefulWidget { const StatefulTextField( @@ -25,13 +26,15 @@ class StatefulTextField extends StatefulWidget { class _StatefulTextFieldState extends State { @override Widget build(BuildContext context) { - return CustomTextField( - title: widget.title, - controller: widget.controller, - hintText: widget.hintText, - width: widget.width, - elevation: widget.elevation, - onSubmittedFun: widget.onSubmitted); + return Container( + child: CustomTextField( + title: widget.title, + controller: widget.controller, + hintText: widget.hintText, + width: widget.width, + elevation: widget.elevation, + onSubmittedFun: widget.onSubmitted), + ); } } @@ -73,17 +76,20 @@ class CustomTextField extends StatelessWidget { child: Container( width: width, height: 45, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(8), - ), + decoration: containerDecoration, + + // decoration: BoxDecoration( + // color: Colors.white, + // borderRadius: BorderRadius.circular(8), + // ), child: TextFormField( controller: controller, style: const TextStyle(color: Colors.black), decoration: InputDecoration( hintText: hintText, hintStyle: const TextStyle(fontSize: 12), - contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), + contentPadding: + const EdgeInsets.symmetric(horizontal: 12, vertical: 10), border: InputBorder.none, ), onFieldSubmitted: (_) { diff --git a/lib/pages/common/text_field/custom_web_textfield.dart b/lib/pages/common/text_field/custom_web_textfield.dart index d5c64e8d..630e334b 100644 --- a/lib/pages/common/text_field/custom_web_textfield.dart +++ b/lib/pages/common/text_field/custom_web_textfield.dart @@ -39,11 +39,17 @@ class CustomWebTextField extends StatelessWidget { if (isRequired) Text( '* ', - style: Theme.of(context).textTheme.bodyMedium!.copyWith(color: Colors.red), + style: Theme.of(context) + .textTheme + .bodyMedium! + .copyWith(color: Colors.red), ), Text( textFieldName, - style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.black, fontSize: 13), + style: Theme.of(context) + .textTheme + .bodySmall! + .copyWith(color: Colors.black, fontSize: 13), ), ], ), @@ -53,10 +59,10 @@ class CustomWebTextField extends StatelessWidget { Expanded( child: Text( description ?? '', - style: Theme.of(context) - .textTheme - .bodySmall! - .copyWith(fontSize: 9, fontWeight: FontWeight.w400, color: ColorsManager.textGray), + style: Theme.of(context).textTheme.bodySmall!.copyWith( + fontSize: 9, + fontWeight: FontWeight.w400, + color: ColorsManager.textGray), ), ), ], @@ -66,21 +72,15 @@ class CustomWebTextField extends StatelessWidget { ), Container( height: height ?? 35, - decoration: containerDecoration.copyWith(color: const Color(0xFFF5F6F7), boxShadow: [ - BoxShadow( - color: Colors.grey.withOpacity(0.3), - spreadRadius: 2, - blurRadius: 3, - offset: const Offset(1, 1), // changes position of shadow - ), - ]), + decoration: containerDecoration, child: TextFormField( validator: validator, controller: controller, style: const TextStyle(color: Colors.black), decoration: textBoxDecoration()!.copyWith( errorStyle: const TextStyle(height: 0), - hintStyle: context.textTheme.titleSmall!.copyWith(color: Colors.grey, fontSize: 12), + hintStyle: context.textTheme.titleSmall! + .copyWith(color: Colors.grey, fontSize: 12), hintText: hintText ?? 'Please enter'), onFieldSubmitted: onSubmitted, ), diff --git a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart index 366775bf..49a4dc35 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart @@ -57,12 +57,15 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { 'Low Battery ($lowBatteryCount)', ]; - final buttonLabel = (selectedDevices.length > 1) ? 'Batch Control' : 'Control'; + final buttonLabel = + (selectedDevices.length > 1) ? 'Batch Control' : 'Control'; return Column( children: [ Container( - padding: isLargeScreenSize(context) ? const EdgeInsets.all(30) : const EdgeInsets.all(15), + padding: isLargeScreenSize(context) + ? const EdgeInsets.all(30) + : const EdgeInsets.all(15), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -71,7 +74,9 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { tabs: tabs, selectedIndex: selectedIndex, onTabChanged: (index) { - context.read().add(SelectedFilterChanged(index)); + context + .read() + .add(SelectedFilterChanged(index)); }, ), const SizedBox(height: 20), @@ -93,11 +98,14 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { ), ); } else if (selectedDevices.length > 1) { - final productTypes = selectedDevices.map((device) => device.productType).toSet(); + final productTypes = selectedDevices + .map((device) => device.productType) + .toSet(); if (productTypes.length == 1) { showDialog( context: context, - builder: (context) => DeviceBatchControlDialog( + builder: (context) => + DeviceBatchControlDialog( devices: selectedDevices, ), ); @@ -111,7 +119,9 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { textAlign: TextAlign.center, style: TextStyle( fontSize: 12, - color: isControlButtonEnabled ? Colors.white : Colors.grey, + color: isControlButtonEnabled + ? Colors.white + : Colors.grey, ), ), ), @@ -122,13 +132,17 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { ), Expanded( child: Padding( - padding: isLargeScreenSize(context) ? const EdgeInsets.all(30) : const EdgeInsets.all(15), + padding: isLargeScreenSize(context) + ? const EdgeInsets.all(30) + : const EdgeInsets.all(15), child: DynamicTable( withSelectAll: true, cellDecoration: containerDecoration, onRowSelected: (index, isSelected, row) { final selectedDevice = devicesToShow[index]; - context.read().add(SelectDevice(selectedDevice)); + context + .read() + .add(SelectDevice(selectedDevice)); }, withCheckBox: true, size: MediaQuery.of(context).size, @@ -151,17 +165,26 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { device.uuid ?? '', device.unit?.name ?? '', device.room?.name ?? '', - device.batteryLevel != null ? '${device.batteryLevel}%' : '-', - formatDateTime(DateTime.fromMillisecondsSinceEpoch((device.createTime ?? 0) * 1000)), + device.batteryLevel != null + ? '${device.batteryLevel}%' + : '-', + formatDateTime(DateTime.fromMillisecondsSinceEpoch( + (device.createTime ?? 0) * 1000)), device.online == true ? 'Online' : 'Offline', - formatDateTime(DateTime.fromMillisecondsSinceEpoch((device.updateTime ?? 0) * 1000)), + formatDateTime(DateTime.fromMillisecondsSinceEpoch( + (device.updateTime ?? 0) * 1000)), ]; }).toList(), onSelectionChanged: (selectedRows) { - context.read().add(UpdateSelection(selectedRows)); + context + .read() + .add(UpdateSelection(selectedRows)); }, - initialSelectedIds: - context.read().selectedDevices.map((device) => device.uuid!).toList(), + initialSelectedIds: context + .read() + .selectedDevices + .map((device) => device.uuid!) + .toList(), isEmpty: devicesToShow.isEmpty, ), ), diff --git a/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart b/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart index ddb2bc19..a6c202f4 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_search_filters.dart @@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/common/text_field/custom_text_field.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_managment_bloc.dart'; import 'package:syncrow_web/pages/common/buttons/search_reset_buttons.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; +import 'package:syncrow_web/utils/style.dart'; class DeviceSearchFilters extends StatefulWidget { const DeviceSearchFilters({super.key}); @@ -12,7 +13,8 @@ class DeviceSearchFilters extends StatefulWidget { State createState() => _DeviceSearchFiltersState(); } -class _DeviceSearchFiltersState extends State with HelperResponsiveLayout { +class _DeviceSearchFiltersState extends State + with HelperResponsiveLayout { final TextEditingController communityController = TextEditingController(); final TextEditingController unitNameController = TextEditingController(); final TextEditingController productNameController = TextEditingController(); @@ -34,7 +36,8 @@ class _DeviceSearchFiltersState extends State with HelperRe const SizedBox(width: 20), _buildSearchField("Unit Name", unitNameController, 200), const SizedBox(width: 20), - _buildSearchField("Device Name / Product Name", productNameController, 300), + _buildSearchField( + "Device Name / Product Name", productNameController, 300), const SizedBox(width: 20), _buildSearchResetButtons(), ], @@ -59,19 +62,22 @@ class _DeviceSearchFiltersState extends State with HelperRe ); } - Widget _buildSearchField(String title, TextEditingController controller, double width) { - return StatefulTextField( - title: title, - width: width, - elevation: 2, - controller: controller, - onSubmitted: () { - context.read().add(SearchDevices( - productName: productNameController.text, - unitName: unitNameController.text, - community: communityController.text, - searchField: true)); - }, + Widget _buildSearchField( + String title, TextEditingController controller, double width) { + return Container( + child: StatefulTextField( + title: title, + width: width, + elevation: 2, + controller: controller, + onSubmitted: () { + context.read().add(SearchDevices( + productName: productNameController.text, + unitName: unitNameController.text, + community: communityController.text, + searchField: true)); + }, + ), ); } diff --git a/lib/utils/color_manager.dart b/lib/utils/color_manager.dart index 1eaf8845..9b4692bc 100644 --- a/lib/utils/color_manager.dart +++ b/lib/utils/color_manager.dart @@ -42,4 +42,4 @@ abstract class ColorsManager { static const Color textGreen = Color(0xFF008905); static const Color yaGreen = Color(0xFFFFBF44); } -//0036E6 \ No newline at end of file +//background: #999999; diff --git a/lib/utils/style.dart b/lib/utils/style.dart index bda3665f..145cf8a1 100644 --- a/lib/utils/style.dart +++ b/lib/utils/style.dart @@ -33,12 +33,11 @@ InputDecoration? textBoxDecoration({bool suffixIcon = false}) => BoxDecoration containerDecoration = BoxDecoration( boxShadow: [ BoxShadow( - color: Colors.grey.withOpacity(0.5), - spreadRadius: 5, - blurRadius: 8, - offset: const Offset(0, 3), // changes position of shadow + color: Colors.grey.withOpacity(0.3), + spreadRadius: 2, + blurRadius: 4, + offset: const Offset(0, 5), // changes position of shadow ), ], color: ColorsManager.boxColor, borderRadius: const BorderRadius.all(Radius.circular(10))); - diff --git a/pubspec.lock b/pubspec.lock index 2c9cb88c..8b9df6d6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -292,18 +292,18 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.5" + version: "10.0.4" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" url: "https://pub.dev" source: hosted - version: "3.0.5" + version: "3.0.3" leak_tracker_testing: dependency: transitive description: @@ -340,18 +340,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.11.1" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.15.0" + version: "1.12.0" nested: dependency: transitive description: @@ -561,10 +561,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.7.2" + version: "0.7.0" typed_data: dependency: transitive description: @@ -609,10 +609,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" url: "https://pub.dev" source: hosted - version: "14.2.5" + version: "14.2.1" web: dependency: transitive description: From 19e0c6e7bd28897520b4fa4d2ed7df93dee3403e Mon Sep 17 00:00:00 2001 From: mohammadnemer1 Date: Sun, 27 Oct 2024 15:23:32 +0300 Subject: [PATCH 16/26] Delete pubspec.lock --- pubspec.lock | 650 --------------------------------------------------- 1 file changed, 650 deletions(-) delete mode 100644 pubspec.lock diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 8b9df6d6..00000000 --- a/pubspec.lock +++ /dev/null @@ -1,650 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - args: - dependency: transitive - description: - name: args - sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" - url: "https://pub.dev" - source: hosted - version: "2.5.0" - async: - dependency: transitive - description: - name: async - sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" - url: "https://pub.dev" - source: hosted - version: "2.11.0" - bloc: - dependency: transitive - description: - name: bloc - sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e" - url: "https://pub.dev" - source: hosted - version: "8.1.4" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - characters: - dependency: transitive - description: - name: characters - sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" - url: "https://pub.dev" - source: hosted - version: "1.3.0" - clock: - dependency: transitive - description: - name: clock - sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf - url: "https://pub.dev" - source: hosted - version: "1.1.1" - collection: - dependency: transitive - description: - name: collection - sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a - url: "https://pub.dev" - source: hosted - version: "1.18.0" - cupertino_icons: - dependency: "direct main" - description: - name: cupertino_icons - sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 - url: "https://pub.dev" - source: hosted - version: "1.0.8" - data_table_2: - dependency: "direct main" - description: - name: data_table_2 - sha256: f02ec9b24f44420816a87370ff4f4e533e15b274f6267e4c9a88a585ad1a0473 - url: "https://pub.dev" - source: hosted - version: "2.5.15" - dio: - dependency: "direct main" - description: - name: dio - sha256: e17f6b3097b8c51b72c74c9f071a605c47bcc8893839bd66732457a5ebe73714 - url: "https://pub.dev" - source: hosted - version: "5.5.0+1" - dio_web_adapter: - dependency: transitive - description: - name: dio_web_adapter - sha256: "36c5b2d79eb17cdae41e974b7a8284fec631651d2a6f39a8a2ff22327e90aeac" - url: "https://pub.dev" - source: hosted - version: "1.0.1" - dropdown_button2: - dependency: "direct main" - description: - name: dropdown_button2 - sha256: b0fe8d49a030315e9eef6c7ac84ca964250155a6224d491c1365061bc974a9e1 - url: "https://pub.dev" - source: hosted - version: "2.3.9" - dropdown_search: - dependency: "direct main" - description: - name: dropdown_search - sha256: "55106e8290acaa97ed15bea1fdad82c3cf0c248dd410e651f5a8ac6870f783ab" - url: "https://pub.dev" - source: hosted - version: "5.0.6" - equatable: - dependency: "direct main" - description: - name: equatable - sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 - url: "https://pub.dev" - source: hosted - version: "2.0.5" - fake_async: - dependency: transitive - description: - name: fake_async - sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" - url: "https://pub.dev" - source: hosted - version: "1.3.1" - ffi: - dependency: transitive - description: - name: ffi - sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" - url: "https://pub.dev" - source: hosted - version: "2.1.2" - file: - dependency: transitive - description: - name: file - sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" - url: "https://pub.dev" - source: hosted - version: "7.0.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_bloc: - dependency: "direct main" - description: - name: flutter_bloc - sha256: f0ecf6e6eb955193ca60af2d5ca39565a86b8a142452c5b24d96fb477428f4d2 - url: "https://pub.dev" - source: hosted - version: "8.1.5" - flutter_dotenv: - dependency: "direct main" - description: - name: flutter_dotenv - sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77" - url: "https://pub.dev" - source: hosted - version: "5.1.0" - flutter_lints: - dependency: "direct dev" - description: - name: flutter_lints - sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1" - url: "https://pub.dev" - source: hosted - version: "3.0.2" - flutter_secure_storage: - dependency: "direct main" - description: - name: flutter_secure_storage - sha256: "165164745e6afb5c0e3e3fcc72a012fb9e58496fb26ffb92cf22e16a821e85d0" - url: "https://pub.dev" - source: hosted - version: "9.2.2" - flutter_secure_storage_linux: - dependency: transitive - description: - name: flutter_secure_storage_linux - sha256: "4d91bfc23047422cbcd73ac684bc169859ee766482517c22172c86596bf1464b" - url: "https://pub.dev" - source: hosted - version: "1.2.1" - flutter_secure_storage_macos: - dependency: transitive - description: - name: flutter_secure_storage_macos - sha256: "1693ab11121a5f925bbea0be725abfcfbbcf36c1e29e571f84a0c0f436147a81" - url: "https://pub.dev" - source: hosted - version: "3.1.2" - flutter_secure_storage_platform_interface: - dependency: transitive - description: - name: flutter_secure_storage_platform_interface - sha256: cf91ad32ce5adef6fba4d736a542baca9daf3beac4db2d04be350b87f69ac4a8 - url: "https://pub.dev" - source: hosted - version: "1.1.2" - flutter_secure_storage_web: - dependency: transitive - description: - name: flutter_secure_storage_web - sha256: f4ebff989b4f07b2656fb16b47852c0aab9fed9b4ec1c70103368337bc1886a9 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - flutter_secure_storage_windows: - dependency: transitive - description: - name: flutter_secure_storage_windows - sha256: b20b07cb5ed4ed74fc567b78a72936203f587eba460af1df11281c9326cd3709 - url: "https://pub.dev" - source: hosted - version: "3.1.2" - flutter_svg: - dependency: "direct main" - description: - name: flutter_svg - sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2" - url: "https://pub.dev" - source: hosted - version: "2.0.10+1" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - flutter_web_plugins: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - get_it: - dependency: "direct main" - description: - name: get_it - sha256: d85128a5dae4ea777324730dc65edd9c9f43155c109d5cc0a69cab74139fbac1 - url: "https://pub.dev" - source: hosted - version: "7.7.0" - go_router: - dependency: "direct main" - description: - name: go_router - sha256: "2ddb88e9ad56ae15ee144ed10e33886777eb5ca2509a914850a5faa7b52ff459" - url: "https://pub.dev" - source: hosted - version: "14.2.7" - graphview: - dependency: "direct main" - description: - name: graphview - sha256: bdba183583b23c30c71edea09ad5f0beef612572d3e39e855467a925bd08392f - url: "https://pub.dev" - source: hosted - version: "1.2.0" - http: - dependency: transitive - description: - name: http - sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 - url: "https://pub.dev" - source: hosted - version: "1.2.2" - http_parser: - dependency: transitive - description: - name: http_parser - sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" - url: "https://pub.dev" - source: hosted - version: "4.0.2" - intl: - dependency: "direct main" - description: - name: intl - sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf - url: "https://pub.dev" - source: hosted - version: "0.19.0" - js: - dependency: transitive - description: - name: js - sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 - url: "https://pub.dev" - source: hosted - version: "0.6.7" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" - url: "https://pub.dev" - source: hosted - version: "10.0.4" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" - url: "https://pub.dev" - source: hosted - version: "3.0.3" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" - url: "https://pub.dev" - source: hosted - version: "3.0.1" - lints: - dependency: transitive - description: - name: lints - sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 - url: "https://pub.dev" - source: hosted - version: "3.0.0" - logging: - dependency: transitive - description: - name: logging - sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - matcher: - dependency: transitive - description: - name: matcher - sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb - url: "https://pub.dev" - source: hosted - version: "0.12.16+1" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" - url: "https://pub.dev" - source: hosted - version: "0.8.0" - meta: - dependency: transitive - description: - name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" - url: "https://pub.dev" - source: hosted - version: "1.12.0" - nested: - dependency: transitive - description: - name: nested - sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" - url: "https://pub.dev" - source: hosted - version: "1.0.0" - path: - dependency: transitive - description: - name: path - sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" - url: "https://pub.dev" - source: hosted - version: "1.9.0" - path_parsing: - dependency: transitive - description: - name: path_parsing - sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf - url: "https://pub.dev" - source: hosted - version: "1.0.1" - path_provider: - dependency: transitive - description: - name: path_provider - sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161 - url: "https://pub.dev" - source: hosted - version: "2.1.3" - path_provider_android: - dependency: transitive - description: - name: path_provider_android - sha256: e84c8a53fe1510ef4582f118c7b4bdf15b03002b51d7c2b66983c65843d61193 - url: "https://pub.dev" - source: hosted - version: "2.2.8" - path_provider_foundation: - dependency: transitive - description: - name: path_provider_foundation - sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16 - url: "https://pub.dev" - source: hosted - version: "2.4.0" - path_provider_linux: - dependency: transitive - description: - name: path_provider_linux - sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 - url: "https://pub.dev" - source: hosted - version: "2.2.1" - path_provider_platform_interface: - dependency: transitive - description: - name: path_provider_platform_interface - sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" - url: "https://pub.dev" - source: hosted - version: "2.1.2" - path_provider_windows: - dependency: transitive - description: - name: path_provider_windows - sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 - url: "https://pub.dev" - source: hosted - version: "2.3.0" - petitparser: - dependency: transitive - description: - name: petitparser - sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 - url: "https://pub.dev" - source: hosted - version: "6.0.2" - platform: - dependency: transitive - description: - name: platform - sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65" - url: "https://pub.dev" - source: hosted - version: "3.1.5" - plugin_platform_interface: - dependency: transitive - description: - name: plugin_platform_interface - sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" - url: "https://pub.dev" - source: hosted - version: "2.1.8" - provider: - dependency: transitive - description: - name: provider - sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c - url: "https://pub.dev" - source: hosted - version: "6.1.2" - shared_preferences: - dependency: "direct main" - description: - name: shared_preferences - sha256: c3f888ba2d659f3e75f4686112cc1e71f46177f74452d40d8307edc332296ead - url: "https://pub.dev" - source: hosted - version: "2.3.0" - shared_preferences_android: - dependency: transitive - description: - name: shared_preferences_android - sha256: "041be4d9d2dc6079cf342bc8b761b03787e3b71192d658220a56cac9c04a0294" - url: "https://pub.dev" - source: hosted - version: "2.3.0" - shared_preferences_foundation: - dependency: transitive - description: - name: shared_preferences_foundation - sha256: "671e7a931f55a08aa45be2a13fe7247f2a41237897df434b30d2012388191833" - url: "https://pub.dev" - source: hosted - version: "2.5.0" - shared_preferences_linux: - dependency: transitive - description: - name: shared_preferences_linux - sha256: "2ba0510d3017f91655b7543e9ee46d48619de2a2af38e5c790423f7007c7ccc1" - url: "https://pub.dev" - source: hosted - version: "2.4.0" - shared_preferences_platform_interface: - dependency: transitive - description: - name: shared_preferences_platform_interface - sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80" - url: "https://pub.dev" - source: hosted - version: "2.4.1" - shared_preferences_web: - dependency: transitive - description: - name: shared_preferences_web - sha256: "3a293170d4d9403c3254ee05b84e62e8a9b3c5808ebd17de6a33fe9ea6457936" - url: "https://pub.dev" - source: hosted - version: "2.4.0" - shared_preferences_windows: - dependency: transitive - description: - name: shared_preferences_windows - sha256: "398084b47b7f92110683cac45c6dc4aae853db47e470e5ddcd52cab7f7196ab2" - url: "https://pub.dev" - source: hosted - version: "2.4.0" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" - url: "https://pub.dev" - source: hosted - version: "1.10.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" - url: "https://pub.dev" - source: hosted - version: "1.11.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 - url: "https://pub.dev" - source: hosted - version: "2.1.2" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" - url: "https://pub.dev" - source: hosted - version: "1.2.0" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 - url: "https://pub.dev" - source: hosted - version: "1.2.1" - test_api: - dependency: transitive - description: - name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" - url: "https://pub.dev" - source: hosted - version: "0.7.0" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c - url: "https://pub.dev" - source: hosted - version: "1.3.2" - vector_graphics: - dependency: transitive - description: - name: vector_graphics - sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3" - url: "https://pub.dev" - source: hosted - version: "1.1.11+1" - vector_graphics_codec: - dependency: transitive - description: - name: vector_graphics_codec - sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da - url: "https://pub.dev" - source: hosted - version: "1.1.11+1" - vector_graphics_compiler: - dependency: transitive - description: - name: vector_graphics_compiler - sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81" - url: "https://pub.dev" - source: hosted - version: "1.1.11+1" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" - url: "https://pub.dev" - source: hosted - version: "14.2.1" - web: - dependency: transitive - description: - name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" - url: "https://pub.dev" - source: hosted - version: "0.5.1" - win32: - dependency: transitive - description: - name: win32 - sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4 - url: "https://pub.dev" - source: hosted - version: "5.5.1" - xdg_directories: - dependency: transitive - description: - name: xdg_directories - sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d - url: "https://pub.dev" - source: hosted - version: "1.0.4" - xml: - dependency: transitive - description: - name: xml - sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 - url: "https://pub.dev" - source: hosted - version: "6.5.0" -sdks: - dart: ">=3.4.0 <4.0.0" - flutter: ">=3.22.0" From 5fff4445ac6a0b33629d178e5b1484bb2532ef2b Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sun, 27 Oct 2024 23:09:33 +0300 Subject: [PATCH 17/26] Added pubspec.lock file --- pubspec.lock | 650 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 650 insertions(+) create mode 100644 pubspec.lock diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 00000000..757bcb1b --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,650 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + args: + dependency: transitive + description: + name: args + sha256: "7cf60b9f0cc88203c5a190b4cd62a99feea42759a7fa695010eb5de1c0b2252a" + url: "https://pub.dev" + source: hosted + version: "2.5.0" + async: + dependency: transitive + description: + name: async + sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c" + url: "https://pub.dev" + source: hosted + version: "2.11.0" + bloc: + dependency: transitive + description: + name: bloc + sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e" + url: "https://pub.dev" + source: hosted + version: "8.1.4" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" + url: "https://pub.dev" + source: hosted + version: "2.1.1" + characters: + dependency: transitive + description: + name: characters + sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605" + url: "https://pub.dev" + source: hosted + version: "1.3.0" + clock: + dependency: transitive + description: + name: clock + sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf + url: "https://pub.dev" + source: hosted + version: "1.1.1" + collection: + dependency: transitive + description: + name: collection + sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a + url: "https://pub.dev" + source: hosted + version: "1.18.0" + cupertino_icons: + dependency: "direct main" + description: + name: cupertino_icons + sha256: ba631d1c7f7bef6b729a622b7b752645a2d076dba9976925b8f25725a30e1ee6 + url: "https://pub.dev" + source: hosted + version: "1.0.8" + data_table_2: + dependency: "direct main" + description: + name: data_table_2 + sha256: f02ec9b24f44420816a87370ff4f4e533e15b274f6267e4c9a88a585ad1a0473 + url: "https://pub.dev" + source: hosted + version: "2.5.15" + dio: + dependency: "direct main" + description: + name: dio + sha256: e17f6b3097b8c51b72c74c9f071a605c47bcc8893839bd66732457a5ebe73714 + url: "https://pub.dev" + source: hosted + version: "5.5.0+1" + dio_web_adapter: + dependency: transitive + description: + name: dio_web_adapter + sha256: "36c5b2d79eb17cdae41e974b7a8284fec631651d2a6f39a8a2ff22327e90aeac" + url: "https://pub.dev" + source: hosted + version: "1.0.1" + dropdown_button2: + dependency: "direct main" + description: + name: dropdown_button2 + sha256: b0fe8d49a030315e9eef6c7ac84ca964250155a6224d491c1365061bc974a9e1 + url: "https://pub.dev" + source: hosted + version: "2.3.9" + dropdown_search: + dependency: "direct main" + description: + name: dropdown_search + sha256: "55106e8290acaa97ed15bea1fdad82c3cf0c248dd410e651f5a8ac6870f783ab" + url: "https://pub.dev" + source: hosted + version: "5.0.6" + equatable: + dependency: "direct main" + description: + name: equatable + sha256: c2b87cb7756efdf69892005af546c56c0b5037f54d2a88269b4f347a505e3ca2 + url: "https://pub.dev" + source: hosted + version: "2.0.5" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" + url: "https://pub.dev" + source: hosted + version: "1.3.1" + ffi: + dependency: transitive + description: + name: ffi + sha256: "493f37e7df1804778ff3a53bd691d8692ddf69702cf4c1c1096a2e41b4779e21" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + file: + dependency: transitive + description: + name: file + sha256: "5fc22d7c25582e38ad9a8515372cd9a93834027aacf1801cf01164dac0ffa08c" + url: "https://pub.dev" + source: hosted + version: "7.0.0" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_bloc: + dependency: "direct main" + description: + name: flutter_bloc + sha256: f0ecf6e6eb955193ca60af2d5ca39565a86b8a142452c5b24d96fb477428f4d2 + url: "https://pub.dev" + source: hosted + version: "8.1.5" + flutter_dotenv: + dependency: "direct main" + description: + name: flutter_dotenv + sha256: "9357883bdd153ab78cbf9ffa07656e336b8bbb2b5a3ca596b0b27e119f7c7d77" + url: "https://pub.dev" + source: hosted + version: "5.1.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + flutter_secure_storage: + dependency: "direct main" + description: + name: flutter_secure_storage + sha256: "165164745e6afb5c0e3e3fcc72a012fb9e58496fb26ffb92cf22e16a821e85d0" + url: "https://pub.dev" + source: hosted + version: "9.2.2" + flutter_secure_storage_linux: + dependency: transitive + description: + name: flutter_secure_storage_linux + sha256: "4d91bfc23047422cbcd73ac684bc169859ee766482517c22172c86596bf1464b" + url: "https://pub.dev" + source: hosted + version: "1.2.1" + flutter_secure_storage_macos: + dependency: transitive + description: + name: flutter_secure_storage_macos + sha256: "1693ab11121a5f925bbea0be725abfcfbbcf36c1e29e571f84a0c0f436147a81" + url: "https://pub.dev" + source: hosted + version: "3.1.2" + flutter_secure_storage_platform_interface: + dependency: transitive + description: + name: flutter_secure_storage_platform_interface + sha256: cf91ad32ce5adef6fba4d736a542baca9daf3beac4db2d04be350b87f69ac4a8 + url: "https://pub.dev" + source: hosted + version: "1.1.2" + flutter_secure_storage_web: + dependency: transitive + description: + name: flutter_secure_storage_web + sha256: f4ebff989b4f07b2656fb16b47852c0aab9fed9b4ec1c70103368337bc1886a9 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + flutter_secure_storage_windows: + dependency: transitive + description: + name: flutter_secure_storage_windows + sha256: b20b07cb5ed4ed74fc567b78a72936203f587eba460af1df11281c9326cd3709 + url: "https://pub.dev" + source: hosted + version: "3.1.2" + flutter_svg: + dependency: "direct main" + description: + name: flutter_svg + sha256: "7b4ca6cf3304575fe9c8ec64813c8d02ee41d2afe60bcfe0678bcb5375d596a2" + url: "https://pub.dev" + source: hosted + version: "2.0.10+1" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + get_it: + dependency: "direct main" + description: + name: get_it + sha256: d85128a5dae4ea777324730dc65edd9c9f43155c109d5cc0a69cab74139fbac1 + url: "https://pub.dev" + source: hosted + version: "7.7.0" + go_router: + dependency: "direct main" + description: + name: go_router + sha256: "2ddb88e9ad56ae15ee144ed10e33886777eb5ca2509a914850a5faa7b52ff459" + url: "https://pub.dev" + source: hosted + version: "14.2.7" + graphview: + dependency: "direct main" + description: + name: graphview + sha256: bdba183583b23c30c71edea09ad5f0beef612572d3e39e855467a925bd08392f + url: "https://pub.dev" + source: hosted + version: "1.2.0" + http: + dependency: transitive + description: + name: http + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 + url: "https://pub.dev" + source: hosted + version: "1.2.2" + http_parser: + dependency: transitive + description: + name: http_parser + sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b" + url: "https://pub.dev" + source: hosted + version: "4.0.2" + intl: + dependency: "direct main" + description: + name: intl + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf + url: "https://pub.dev" + source: hosted + version: "0.19.0" + js: + dependency: transitive + description: + name: js + sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3 + url: "https://pub.dev" + source: hosted + version: "0.6.7" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" + url: "https://pub.dev" + source: hosted + version: "10.0.5" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" + url: "https://pub.dev" + source: hosted + version: "3.0.5" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + url: "https://pub.dev" + source: hosted + version: "3.0.1" + lints: + dependency: transitive + description: + name: lints + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 + url: "https://pub.dev" + source: hosted + version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: "623a88c9594aa774443aa3eb2d41807a48486b5613e67599fb4c41c0ad47c340" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb + url: "https://pub.dev" + source: hosted + version: "0.12.16+1" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" + source: hosted + version: "0.11.1" + meta: + dependency: transitive + description: + name: meta + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 + url: "https://pub.dev" + source: hosted + version: "1.15.0" + nested: + dependency: transitive + description: + name: nested + sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20" + url: "https://pub.dev" + source: hosted + version: "1.0.0" + path: + dependency: transitive + description: + name: path + sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af" + url: "https://pub.dev" + source: hosted + version: "1.9.0" + path_parsing: + dependency: transitive + description: + name: path_parsing + sha256: e3e67b1629e6f7e8100b367d3db6ba6af4b1f0bb80f64db18ef1fbabd2fa9ccf + url: "https://pub.dev" + source: hosted + version: "1.0.1" + path_provider: + dependency: transitive + description: + name: path_provider + sha256: c9e7d3a4cd1410877472158bee69963a4579f78b68c65a2b7d40d1a7a88bb161 + url: "https://pub.dev" + source: hosted + version: "2.1.3" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: e84c8a53fe1510ef4582f118c7b4bdf15b03002b51d7c2b66983c65843d61193 + url: "https://pub.dev" + source: hosted + version: "2.2.8" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: f234384a3fdd67f989b4d54a5d73ca2a6c422fa55ae694381ae0f4375cd1ea16 + url: "https://pub.dev" + source: hosted + version: "2.4.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 + url: "https://pub.dev" + source: hosted + version: "2.2.1" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 + url: "https://pub.dev" + source: hosted + version: "2.3.0" + petitparser: + dependency: transitive + description: + name: petitparser + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 + url: "https://pub.dev" + source: hosted + version: "6.0.2" + platform: + dependency: transitive + description: + name: platform + sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65" + url: "https://pub.dev" + source: hosted + version: "3.1.5" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" + provider: + dependency: transitive + description: + name: provider + sha256: c8a055ee5ce3fd98d6fc872478b03823ffdb448699c6ebdbbc71d59b596fd48c + url: "https://pub.dev" + source: hosted + version: "6.1.2" + shared_preferences: + dependency: "direct main" + description: + name: shared_preferences + sha256: c3f888ba2d659f3e75f4686112cc1e71f46177f74452d40d8307edc332296ead + url: "https://pub.dev" + source: hosted + version: "2.3.0" + shared_preferences_android: + dependency: transitive + description: + name: shared_preferences_android + sha256: "041be4d9d2dc6079cf342bc8b761b03787e3b71192d658220a56cac9c04a0294" + url: "https://pub.dev" + source: hosted + version: "2.3.0" + shared_preferences_foundation: + dependency: transitive + description: + name: shared_preferences_foundation + sha256: "671e7a931f55a08aa45be2a13fe7247f2a41237897df434b30d2012388191833" + url: "https://pub.dev" + source: hosted + version: "2.5.0" + shared_preferences_linux: + dependency: transitive + description: + name: shared_preferences_linux + sha256: "2ba0510d3017f91655b7543e9ee46d48619de2a2af38e5c790423f7007c7ccc1" + url: "https://pub.dev" + source: hosted + version: "2.4.0" + shared_preferences_platform_interface: + dependency: transitive + description: + name: shared_preferences_platform_interface + sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80" + url: "https://pub.dev" + source: hosted + version: "2.4.1" + shared_preferences_web: + dependency: transitive + description: + name: shared_preferences_web + sha256: "3a293170d4d9403c3254ee05b84e62e8a9b3c5808ebd17de6a33fe9ea6457936" + url: "https://pub.dev" + source: hosted + version: "2.4.0" + shared_preferences_windows: + dependency: transitive + description: + name: shared_preferences_windows + sha256: "398084b47b7f92110683cac45c6dc4aae853db47e470e5ddcd52cab7f7196ab2" + url: "https://pub.dev" + source: hosted + version: "2.4.0" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.99" + source_span: + dependency: transitive + description: + name: source_span + sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c" + url: "https://pub.dev" + source: hosted + version: "1.10.0" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b" + url: "https://pub.dev" + source: hosted + version: "1.11.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7 + url: "https://pub.dev" + source: hosted + version: "2.1.2" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" + url: "https://pub.dev" + source: hosted + version: "1.2.0" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 + url: "https://pub.dev" + source: hosted + version: "1.2.1" + test_api: + dependency: transitive + description: + name: test_api + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" + url: "https://pub.dev" + source: hosted + version: "0.7.2" + typed_data: + dependency: transitive + description: + name: typed_data + sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c + url: "https://pub.dev" + source: hosted + version: "1.3.2" + vector_graphics: + dependency: transitive + description: + name: vector_graphics + sha256: "32c3c684e02f9bc0afb0ae0aa653337a2fe022e8ab064bcd7ffda27a74e288e3" + url: "https://pub.dev" + source: hosted + version: "1.1.11+1" + vector_graphics_codec: + dependency: transitive + description: + name: vector_graphics_codec + sha256: c86987475f162fadff579e7320c7ddda04cd2fdeffbe1129227a85d9ac9e03da + url: "https://pub.dev" + source: hosted + version: "1.1.11+1" + vector_graphics_compiler: + dependency: transitive + description: + name: vector_graphics_compiler + sha256: "12faff3f73b1741a36ca7e31b292ddeb629af819ca9efe9953b70bd63fc8cd81" + url: "https://pub.dev" + source: hosted + version: "1.1.11+1" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" + url: "https://pub.dev" + source: hosted + version: "14.2.5" + web: + dependency: transitive + description: + name: web + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + url: "https://pub.dev" + source: hosted + version: "0.5.1" + win32: + dependency: transitive + description: + name: win32 + sha256: a79dbe579cb51ecd6d30b17e0cae4e0ea15e2c0e66f69ad4198f22a6789e94f4 + url: "https://pub.dev" + source: hosted + version: "5.5.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: faea9dee56b520b55a566385b84f2e8de55e7496104adada9962e0bd11bcff1d + url: "https://pub.dev" + source: hosted + version: "1.0.4" + xml: + dependency: transitive + description: + name: xml + sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226 + url: "https://pub.dev" + source: hosted + version: "6.5.0" +sdks: + dart: ">=3.4.0 <4.0.0" + flutter: ">=3.22.0" \ No newline at end of file From c4421a9ef30de2705452b1ad437e690dc06e067d Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sun, 27 Oct 2024 23:12:38 +0300 Subject: [PATCH 18/26] Edited pubspec.lock file --- pubspec.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.lock b/pubspec.lock index 757bcb1b..2c9cb88c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -647,4 +647,4 @@ packages: version: "6.5.0" sdks: dart: ">=3.4.0 <4.0.0" - flutter: ">=3.22.0" \ No newline at end of file + flutter: ">=3.22.0" From 9dda21075e375c34ed70310dfe651577f422f8b2 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sun, 27 Oct 2024 23:39:00 +0300 Subject: [PATCH 19/26] Updated the pubspec.lock --- pubspec.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index fa61b407..978bec23 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -303,15 +303,15 @@ packages: sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" url: "https://pub.dev" source: hosted - version: "10.0.4" + version: "10.0.5" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8" + sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806" url: "https://pub.dev" source: hosted - version: "3.0.3" + version: "3.0.5" leak_tracker_testing: dependency: transitive description: @@ -348,18 +348,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" + sha256: "f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec" url: "https://pub.dev" source: hosted - version: "0.8.0" + version: "0.11.1" meta: dependency: transitive description: name: meta - sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" + sha256: "bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7" url: "https://pub.dev" source: hosted - version: "1.12.0" + version: "1.15.0" nested: dependency: transitive description: @@ -569,10 +569,10 @@ packages: dependency: transitive description: name: test_api - sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" + sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb" url: "https://pub.dev" source: hosted - version: "0.7.0" + version: "0.7.2" typed_data: dependency: transitive description: @@ -617,10 +617,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec" + sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d" url: "https://pub.dev" source: hosted - version: "14.2.1" + version: "14.2.5" web: dependency: transitive description: From 8775258160bf810f348e1975f5903a25b0671827 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Sun, 27 Oct 2024 23:41:26 +0300 Subject: [PATCH 20/26] Updated the pubspec.lock --- pubspec.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 978bec23..92a76b10 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -300,7 +300,7 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a" + sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05" url: "https://pub.dev" source: hosted version: "10.0.5" @@ -348,7 +348,7 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec" + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec url: "https://pub.dev" source: hosted version: "0.11.1" @@ -356,7 +356,7 @@ packages: dependency: transitive description: name: meta - sha256: "bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7" + sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7 url: "https://pub.dev" source: hosted version: "1.15.0" From 0425b19478e472fbb1fd5dcca0943ef62134311c Mon Sep 17 00:00:00 2001 From: mohammad Date: Mon, 28 Oct 2024 13:17:48 +0300 Subject: [PATCH 21/26] power_clamp_issue --- assets/icons/voltage_icon.svg | 41 +++ .../power_clamp/bloc/smart_power_bloc.dart | 80 +++-- .../power_clamp/bloc/smart_power_state.dart | 2 + .../power_clamp/view/power_chart.dart | 318 +++++++++--------- .../view/smart_power_device_control.dart | 27 +- lib/services/devices_mang_api.dart | 1 - 6 files changed, 255 insertions(+), 214 deletions(-) create mode 100644 assets/icons/voltage_icon.svg 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; }, ); From 81913dca9fe858bc58631365fbe6289c18f47998 Mon Sep 17 00:00:00 2001 From: mohammad Date: Tue, 29 Oct 2024 09:43:09 +0300 Subject: [PATCH 22/26] power_clamp_issue --- .../power_clamp/bloc/smart_power_bloc.dart | 10 ++---- .../power_clamp/view/power_chart.dart | 34 +++++++++++-------- .../view/power_clamp_batch_control_view.dart | 3 +- 3 files changed, 23 insertions(+), 24 deletions(-) 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 842dbc97..04cb1b54 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 @@ -589,16 +589,14 @@ class SmartPowerBloc extends Bloc { TextButton( child: const Text('Cancel'), onPressed: () { - Navigator.of(context) - .pop(); // Pops without value, returning null + Navigator.of(context) .pop(); }, ), 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); }, ), ], @@ -681,8 +679,6 @@ class SmartPowerBloc extends Bloc { SelectDateEvent event, Emitter emit) async { Future Function(BuildContext context)? dateSelector; String dateFormat; - - // Determine which picker to use and format to apply switch (currentIndex) { case 0: dateSelector = (context) { @@ -723,7 +719,6 @@ class SmartPowerBloc extends Bloc { }); emit(FilterRecordsState(filteredRecords: energyDataList)); - // emit(DateSelectedState()); } List energyDataList = []; @@ -778,6 +773,7 @@ class SmartPowerBloc extends Bloc { } String endChartDate = ''; + void selectDateRange() async { DateTime startDate = dateTime!; DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1) 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 dc632478..273537ba 100644 --- a/lib/pages/device_managment/power_clamp/view/power_chart.dart +++ b/lib/pages/device_managment/power_clamp/view/power_chart.dart @@ -95,7 +95,7 @@ class _EnergyConsumptionPageState extends State { Padding( padding: const EdgeInsets.only(top: 15), child: SizedBox( - height: MediaQuery.of(context).size.height * 0.15, + height: MediaQuery.of(context).size.height * 0.12, child: LineChart( LineChartData( lineTouchData: LineTouchData( @@ -240,20 +240,24 @@ class _EnergyConsumptionPageState extends State { child: Container(child: widget.widget), ), ), - 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), + SizedBox( + width: 20, + ), + Expanded( + 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: SizedBox( + child: Padding( + padding: const EdgeInsets.all(5), + child: Text(widget.date), + ), ), ), ), diff --git a/lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart b/lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart index 886ae5b1..c0244845 100644 --- a/lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart +++ b/lib/pages/device_managment/power_clamp/view/power_clamp_batch_control_view.dart @@ -5,7 +5,6 @@ import 'package:syncrow_web/pages/device_managment/power_clamp/bloc/smart_power_ 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/power_clamp_batch_model.dart'; -import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_model.dart'; import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart'; import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; @@ -45,7 +44,7 @@ class PowerClampBatchControlView extends StatelessWidget children: [ SizedBox( width: 170, - height: 140, + // height: 140, child: FirmwareUpdateWidget(deviceId: deviceIds.first, version: 2)), const SizedBox( width: 12, From 4eb214e0109c923b045436ecdbc06e47661253b4 Mon Sep 17 00:00:00 2001 From: mohammad Date: Tue, 29 Oct 2024 10:50:44 +0300 Subject: [PATCH 23/26] remove_file --- .../view/wall_light_batch_control.dart | 92 ------------------- 1 file changed, 92 deletions(-) delete mode 100644 lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart diff --git a/lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart b/lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart deleted file mode 100644 index e1dabb61..00000000 --- a/lib/pages/device_managment/power_clamp/view/wall_light_batch_control.dart +++ /dev/null @@ -1,92 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart'; -import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_bloc.dart'; -import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_event.dart'; -import 'package:syncrow_web/pages/device_managment/one_gang_switch/bloc/wall_light_switch_state.dart'; -import 'package:syncrow_web/pages/device_managment/one_gang_switch/models/wall_light_status_model.dart'; -import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart'; -import 'package:syncrow_web/pages/device_managment/shared/batch_control/firmware_update.dart'; -import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart'; -import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; - -class WallLightBatchControlView extends StatelessWidget - with HelperResponsiveLayout { - const WallLightBatchControlView({super.key, required this.deviceIds}); - - final List deviceIds; - - @override - Widget build(BuildContext context) { - return BlocProvider( - create: (context) => WallLightSwitchBloc(deviceId: deviceIds.first) - ..add(WallLightSwitchFetchBatchEvent(deviceIds)), - child: BlocBuilder( - builder: (context, state) { - if (state is WallLightSwitchLoading) { - return const Center(child: CircularProgressIndicator()); - } else if (state is WallLightSwitchStatusLoaded) { - 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, WallLightStatusModel status) { - final isExtraLarge = isExtraLargeScreenSize(context); - final isLarge = isLargeScreenSize(context); - final isMedium = isMediumScreenSize(context); - return SizedBox( - child: GridView( - padding: const EdgeInsets.symmetric(horizontal: 50), - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( - crossAxisCount: isLarge || isExtraLarge - ? 3 - : isMedium - ? 2 - : 1, - mainAxisExtent: 140, - crossAxisSpacing: 12, - mainAxisSpacing: 12, - ), - children: [ - ToggleWidget( - value: status.switch1, - code: 'switch_1', - deviceId: deviceIds.first, - label: 'Wall Light', - onChange: (value) { - context.read().add( - WallLightSwitchBatchControl( - devicesIds: deviceIds, - code: 'switch_1', - value: value, - ), - ); - }, - ), - FirmwareUpdateWidget( - deviceId: deviceIds.first, - version: 12, - ), - FactoryResetWidget( - callFactoryReset: () { - context.read().add(WallLightFactoryReset( - deviceId: status.uuid, - factoryReset: FactoryResetModel(devicesUuid: deviceIds))); - }, - ), - ], - ), - ); - } -} From 29a2e9285b681ff85bb8eae098758d7f25daf0bd Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Wed, 30 Oct 2024 00:46:48 +0300 Subject: [PATCH 24/26] enhancement and bug fixes --- lib/pages/common/custom_table.dart | 9 +- .../power_clamp/bloc/smart_power_bloc.dart | 326 +++++------------- .../power_clamp/bloc/smart_power_state.dart | 3 + .../power_clamp/view/power_info_card.dart | 103 +++--- .../view/smart_power_device_control.dart | 49 ++- .../shared/batch_control/factory_reset.dart | 9 +- 6 files changed, 173 insertions(+), 326 deletions(-) diff --git a/lib/pages/common/custom_table.dart b/lib/pages/common/custom_table.dart index 10171c33..22baba36 100644 --- a/lib/pages/common/custom_table.dart +++ b/lib/pages/common/custom_table.dart @@ -131,7 +131,10 @@ class _DynamicTableState extends State { child: Row( children: [ if (widget.withCheckBox) _buildSelectAllCheckbox(), - ...widget.headers.map((header) => _buildTableHeaderCell(header)), + ...List.generate(widget.headers.length, (index) { + return _buildTableHeaderCell(widget.headers[index], index); + }) + //...widget.headers.map((header) => _buildTableHeaderCell(header)), ], ), ), @@ -224,7 +227,7 @@ class _DynamicTableState extends State { ); } - Widget _buildTableHeaderCell(String title) { + Widget _buildTableHeaderCell(String title, int index) { return Expanded( child: Container( decoration: const BoxDecoration( @@ -235,7 +238,7 @@ class _DynamicTableState extends State { constraints: const BoxConstraints.expand(height: 40), alignment: Alignment.centerLeft, child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4), + padding: EdgeInsets.symmetric(horizontal: index == widget.headers.length - 1 ? 12 : 8.0, vertical: 4), child: Text( title, style: context.textTheme.titleSmall!.copyWith( 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 04cb1b54..3928fb51 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,6 @@ import 'dart:async'; + import 'package:flutter/cupertino.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:intl/intl.dart'; @@ -33,190 +33,56 @@ class SmartPowerBloc extends Bloc { int currentPage = 0; List record = [ - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:15:43'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:15:35'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:15:29'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:15:25'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:15:21'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:15:17'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:15:07'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:14:47'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:14:40'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:14:23'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2024-10-23 11:14:13'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:15:43'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:15:35'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:15:29'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:15:25'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:15:21'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:15:17'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:15:07'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:14:47'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:14:40'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:14:23'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-10-23 11:14:13'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:15:43'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:15:35'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:15:29'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:15:25'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:15:21'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:15:17'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:15:07'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:14:47'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:14:40'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:14:23'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-23 11:14:13'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-11 11:15:43'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-11 11:15:35'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-12 11:15:29'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-13 11:15:25'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-14 11:15:21'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-15 11:15:17'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-16 11:15:07'), - value: '2286'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-17 11:14:47'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-18 11:14:40'), - value: '2284'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-19 11:14:23'), - value: '2285'), - EventDevice( - code: 'VoltageA', - eventTime: DateTime.parse('2023-02-20 11:14:13'), - value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:43'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:35'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:29'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:25'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:21'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:17'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:07'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:47'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:40'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:23'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:13'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:43'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:35'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:29'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:25'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:21'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:17'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:07'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:47'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:40'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:23'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:13'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:43'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:35'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:29'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:25'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:21'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:17'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:07'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:47'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:40'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:23'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:13'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-11 11:15:43'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-11 11:15:35'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-12 11:15:29'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-13 11:15:25'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-14 11:15:21'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-15 11:15:17'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-16 11:15:07'), value: '2286'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-17 11:14:47'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-18 11:14:40'), value: '2284'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-19 11:14:23'), value: '2285'), + EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-20 11:14:13'), value: '2284'), ]; - FutureOr _onFetchDeviceStatus( - SmartPowerFetchDeviceEvent event, Emitter emit) async { + FutureOr _onFetchDeviceStatus(SmartPowerFetchDeviceEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - var status = - await DevicesManagementApi().getPowerClampInfo(event.deviceId); + var status = await DevicesManagementApi().getPowerClampInfo(event.deviceId); deviceStatus = PowerClampModel.fromJson(status); phaseData = [ @@ -248,22 +114,19 @@ class SmartPowerBloc extends Bloc { } } - FutureOr _onArrowPressed( - SmartPowerArrowPressedEvent event, Emitter emit) { + FutureOr _onArrowPressed(SmartPowerArrowPressedEvent event, Emitter emit) { currentPage = (currentPage + event.direction + 4) % 4; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); emit(GetDeviceStatus()); } - FutureOr _onPageChanged( - SmartPowerPageChangedEvent event, Emitter emit) { + FutureOr _onPageChanged(SmartPowerPageChangedEvent event, Emitter emit) { currentPage = event.page; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); emit(GetDeviceStatus()); } - Future _onFactoryReset( - SmartPowerFactoryReset event, Emitter emit) async { + Future _onFactoryReset(SmartPowerFactoryReset event, Emitter emit) async { emit(SmartPowerLoading()); try { final response = await DevicesManagementApi().factoryReset( @@ -280,8 +143,7 @@ class SmartPowerBloc extends Bloc { } } - Future _onBatchControl( - PowerBatchControlEvent event, Emitter emit) async { + Future _onBatchControl(PowerBatchControlEvent event, Emitter emit) async { final oldValue = deviceStatus.status; _updateLocalValue(event.code, event.value); @@ -297,14 +159,11 @@ class SmartPowerBloc extends Bloc { ); } - Future _onFetchBatchStatus( - SmartPowerFetchBatchEvent event, Emitter emit) async { + Future _onFetchBatchStatus(SmartPowerFetchBatchEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - final response = - await DevicesManagementApi().getPowerStatus(event.devicesIds); - PowerClampBatchModel deviceStatus = - PowerClampBatchModel.fromJson(response); + final response = await DevicesManagementApi().getPowerStatus(event.devicesIds); + PowerClampBatchModel deviceStatus = PowerClampBatchModel.fromJson(response); emit(SmartPowerLoadBatchControll(deviceStatus)); } catch (e) { @@ -336,11 +195,9 @@ class SmartPowerBloc extends Bloc { try { late bool response; if (isBatch) { - response = await DevicesManagementApi() - .deviceBatchControl(deviceId, code, value); + response = await DevicesManagementApi().deviceBatchControl(deviceId, code, value); } else { - response = await DevicesManagementApi() - .deviceControl(deviceId, Status(code: code, value: value)); + response = await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value)); } if (!response) { @@ -360,8 +217,7 @@ class SmartPowerBloc extends Bloc { } } - void _revertValueAndEmit(String deviceId, String code, dynamic oldValue, - Emitter emit) { + void _revertValueAndEmit(String deviceId, String code, dynamic oldValue, Emitter emit) { _updateLocalValue(code, oldValue); emit(SmartPowerLoadBatchControll(deviceBatchStatus)); } @@ -418,10 +274,8 @@ class SmartPowerBloc extends Bloc { int selectedYear = DateTime.now().year; int selectedMonth = DateTime.now().month; - FixedExtentScrollController yearController = - FixedExtentScrollController(initialItem: selectedYear - 1905); - FixedExtentScrollController monthController = - FixedExtentScrollController(initialItem: selectedMonth - 1); + FixedExtentScrollController yearController = FixedExtentScrollController(initialItem: selectedYear - 1905); + FixedExtentScrollController monthController = FixedExtentScrollController(initialItem: selectedMonth - 1); return await showDialog( context: context, @@ -440,8 +294,7 @@ class SmartPowerBloc extends Bloc { padding: EdgeInsets.all(16.0), child: Text( 'Select Month and Year', - style: - TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), ), const Divider(), @@ -484,8 +337,7 @@ class SmartPowerBloc extends Bloc { builder: (context, index) { return Center( child: Text( - DateFormat.MMMM() - .format(DateTime(0, index + 1)), + DateFormat.MMMM().format(DateTime(0, index + 1)), style: const TextStyle(fontSize: 18), ), ); @@ -500,8 +352,7 @@ class SmartPowerBloc extends Bloc { ), const Divider(), Padding( - padding: const EdgeInsets.symmetric( - horizontal: 16.0, vertical: 8.0), + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -514,8 +365,7 @@ class SmartPowerBloc extends Bloc { TextButton( child: const Text('OK'), onPressed: () { - final selectedDateTime = - DateTime(selectedYear, selectedMonth); + final selectedDateTime = DateTime(selectedYear, selectedMonth); Navigator.of(context).pop(selectedDateTime); }, ), @@ -533,8 +383,7 @@ class SmartPowerBloc extends Bloc { Future selectYear(BuildContext context) async { int selectedYear = DateTime.now().year; - FixedExtentScrollController yearController = - FixedExtentScrollController(initialItem: selectedYear - 1905); + FixedExtentScrollController yearController = FixedExtentScrollController(initialItem: selectedYear - 1905); return await showDialog( context: context, @@ -553,8 +402,7 @@ class SmartPowerBloc extends Bloc { padding: EdgeInsets.all(16.0), child: Text( 'Select Year', - style: - TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), ), const Divider(), @@ -581,22 +429,21 @@ class SmartPowerBloc extends Bloc { ), const Divider(), Padding( - padding: const EdgeInsets.symmetric( - horizontal: 16.0, vertical: 8.0), + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ TextButton( child: const Text('Cancel'), onPressed: () { - Navigator.of(context) .pop(); + Navigator.of(context).pop(); }, ), TextButton( child: const Text('OK'), onPressed: () { final selectedDateTime = DateTime(selectedYear); - Navigator.of(context).pop(selectedDateTime); + Navigator.of(context).pop(selectedDateTime); }, ), ], @@ -624,9 +471,12 @@ class SmartPowerBloc extends Bloc { mainAxisAlignment: MainAxisAlignment.center, children: [ Container( - color: Colors.white, height: 350, width: 350, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + ), child: Column( children: [ Expanded( @@ -642,8 +492,7 @@ class SmartPowerBloc extends Bloc { ), const Divider(), Padding( - padding: const EdgeInsets.symmetric( - horizontal: 16.0, vertical: 8.0), + padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -675,8 +524,7 @@ class SmartPowerBloc extends Bloc { String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now()); - void checkDayMonthYearSelected( - SelectDateEvent event, Emitter emit) async { + void checkDayMonthYearSelected(SelectDateEvent event, Emitter emit) async { Future Function(BuildContext context)? dateSelector; String dateFormat; switch (currentIndex) { @@ -702,7 +550,7 @@ class SmartPowerBloc extends Bloc { return; } Future.delayed(const Duration(milliseconds: 500), () { - emit(SmartPowerLoading()); + emit(FakeState()); }); // Use the selected picker await dateSelector(event.context).then((newDate) { @@ -718,27 +566,21 @@ class SmartPowerBloc extends Bloc { // formattedDate = newDate.toString(); }); emit(FilterRecordsState(filteredRecords: energyDataList)); - } List energyDataList = []; - void _filterRecordsByDate( - FilterRecordsByDateEvent event, Emitter emit) { - emit(SmartPowerLoading()); + void _filterRecordsByDate(FilterRecordsByDateEvent event, Emitter emit) { + // emit(SmartPowerLoading()); if (event.viewType == 'Year') { formattedDate = event.selectedDate.year.toString(); - filteredRecords = record - .where((record) => record.eventTime!.year == event.selectedDate.year) - .toList(); + 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)}"; + 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) + record.eventTime!.year == event.selectedDate.year && record.eventTime!.month == event.selectedDate.month) .toList(); } else if (event.viewType == 'Day') { formattedDate = @@ -756,8 +598,7 @@ class SmartPowerBloc extends Bloc { energyDataList = filteredRecords.map((eventDevice) { return EnergyData( event.viewType == 'Year' - ? getMonthShortName( - int.tryParse(DateFormat('MM').format(eventDevice.eventTime!))!) + ? getMonthShortName(int.tryParse(DateFormat('MM').format(eventDevice.eventTime!))!) : event.viewType == 'Month' ? DateFormat('yyyy/MM/dd').format(eventDevice.eventTime!) : DateFormat('HH:mm:ss').format(eventDevice.eventTime!), @@ -773,11 +614,10 @@ class SmartPowerBloc extends Bloc { } String endChartDate = ''; - + void selectDateRange() async { DateTime startDate = dateTime!; - DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1) - .subtract(Duration(days: 1)); + 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 62af9e78..a46a3223 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,7 @@ class SmartPowerState extends Equatable { class SmartPowerInitial extends SmartPowerState {} class SmartPowerLoading extends SmartPowerState {} + class GetDeviceStatus extends SmartPowerState {} //GetDeviceStatus @@ -25,6 +26,8 @@ class SmartPowerLoadBatchControll extends SmartPowerState { class DateSelectedState extends SmartPowerState {} +class FakeState extends SmartPowerState {} + class SmartPowerStatusLoaded extends SmartPowerState { final PowerClampModel deviceStatus; final int currentPage; 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 b4dd487a..601b6346 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 @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:flutter/painting.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/utils/color_manager.dart'; @@ -20,57 +19,61 @@ class PowerClampInfoCard extends StatelessWidget { @override Widget build(BuildContext context) { return Expanded( - child: Padding( - padding: const EdgeInsets.all(5.0), - child: Container( - decoration: BoxDecoration( - color: ColorsManager.graysColor, - borderRadius: BorderRadius.circular(20), - ), - height: 55, - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - SvgPicture.asset( - iconPath, - fit: BoxFit.fill, - ), - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - title, - style: TextStyle( - fontSize: 8, - fontWeight: FontWeight.w400, + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 6), + decoration: BoxDecoration( + color: ColorsManager.whiteColors, + borderRadius: BorderRadius.circular(20), + ), + height: 55, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + const SizedBox( + width: 16, + ), + SvgPicture.asset( + iconPath, + fit: BoxFit.fill, + ), + const SizedBox( + width: 18, + ), + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + title, + style: const TextStyle( + fontSize: 8, + fontWeight: FontWeight.w400, + ), + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + value, + style: const 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: const 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 635f44ea..8370318a 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 @@ -3,17 +3,16 @@ 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/phase_widget.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 - with HelperResponsiveLayout { +class SmartPowerDeviceControl extends StatelessWidget with HelperResponsiveLayout { final String deviceId; const SmartPowerDeviceControl({super.key, required this.deviceId}); @@ -21,14 +20,19 @@ class SmartPowerDeviceControl extends StatelessWidget @override Widget build(BuildContext context) { return BlocProvider( - create: (context) => SmartPowerBloc(deviceId: deviceId) - ..add(SmartPowerFetchDeviceEvent(deviceId)), + create: (context) => SmartPowerBloc(deviceId: deviceId)..add(SmartPowerFetchDeviceEvent(deviceId)), child: BlocBuilder( builder: (context, state) { final _blocProvider = BlocProvider.of(context); if (state is SmartPowerLoading) { return const Center(child: CircularProgressIndicator()); + } else if (state is FakeState) { + return _buildStatusControls( + currentPage: _blocProvider.currentPage, + context: context, + blocProvider: _blocProvider, + ); } else if (state is GetDeviceStatus) { return _buildStatusControls( currentPage: _blocProvider.currentPage, @@ -56,6 +60,7 @@ class SmartPowerDeviceControl extends StatelessWidget }) { PageController _pageController = PageController(initialPage: currentPage); return Container( + padding: const EdgeInsets.symmetric(horizontal: 50), child: DeviceControlsContainer( child: Column( children: [ @@ -63,62 +68,54 @@ class SmartPowerDeviceControl extends StatelessWidget children: [ Text( 'Live', - style: TextStyle( - fontSize: 32, - fontWeight: FontWeight.w700, - color: ColorsManager.grayColor), + style: TextStyle(fontSize: 32, fontWeight: FontWeight.w700, color: ColorsManager.blackColor), ), ], ), Padding( - padding: const EdgeInsets.all(10.0), + padding: const EdgeInsets.symmetric(vertical: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ PowerClampInfoCard( iconPath: Assets.powerActiveIcon, title: 'Active', - value: blocProvider - .deviceStatus.status.general.dataPoints[2].value - .toString(), + value: blocProvider.deviceStatus.status.general.dataPoints[2].value.toString(), unit: '', ), PowerClampInfoCard( iconPath: Assets.voltMeterIcon, title: 'Current', - value: blocProvider - .deviceStatus.status.general.dataPoints[1].value - .toString(), + value: blocProvider.deviceStatus.status.general.dataPoints[1].value.toString(), unit: ' A', ), PowerClampInfoCard( iconPath: Assets.frequencyIcon, title: 'Frequency', - value: blocProvider - .deviceStatus.status.general.dataPoints[4].value - .toString(), + value: blocProvider.deviceStatus.status.general.dataPoints[4].value.toString(), unit: ' Hz', ), ], ), ), - const SizedBox( - height: 10, - ), PhaseWidget( phaseData: blocProvider.phaseData, ), + const SizedBox( + height: 10, + ), Container( padding: const EdgeInsets.only( top: 10, left: 20, right: 20, + bottom: 10, ), decoration: BoxDecoration( color: ColorsManager.whiteColors, borderRadius: BorderRadius.circular(20), ), - height: 325, + height: 300, child: Column( children: [ Container( @@ -175,14 +172,12 @@ class SmartPowerDeviceControl extends StatelessWidget physics: const NeverScrollableScrollPhysics(), children: [ EnergyConsumptionPage( - formattedDate: - '${blocProvider.formattedDate}${blocProvider.endChartDate}', + formattedDate: '${blocProvider.formattedDate}${blocProvider.endChartDate}', onTap: () { blocProvider.add(SelectDateEvent(context: context)); blocProvider.add(FilterRecordsByDateEvent( selectedDate: blocProvider.dateTime!, - viewType: blocProvider - .views[blocProvider.currentIndex])); + viewType: blocProvider.views[blocProvider.currentIndex])); }, widget: blocProvider.dateSwitcher(), chartData: blocProvider.energyDataList.isNotEmpty diff --git a/lib/pages/device_managment/shared/batch_control/factory_reset.dart b/lib/pages/device_managment/shared/batch_control/factory_reset.dart index ea8f833c..8d1ba3d6 100644 --- a/lib/pages/device_managment/shared/batch_control/factory_reset.dart +++ b/lib/pages/device_managment/shared/batch_control/factory_reset.dart @@ -52,6 +52,7 @@ class _FactoryResetWidgetState extends State { child: DefaultButton( height: 20, elevation: 0, + padding: 0, onPressed: _toggleConfirmation, backgroundColor: ColorsManager.greyColor, child: Text( @@ -69,14 +70,16 @@ class _FactoryResetWidgetState extends State { child: DefaultButton( height: 20, elevation: 0, + padding: 0, onPressed: widget.callFactoryReset, backgroundColor: ColorsManager.red, child: Text( 'Reset', style: context.textTheme.bodyMedium!.copyWith( - color: ColorsManager.whiteColors, - fontWeight: FontWeight.w400, - fontSize: 12), + color: ColorsManager.whiteColors, + fontWeight: FontWeight.w400, + fontSize: 12, + ), ), ), ), From 73ab6f3d05b79e3fff5c891a54ee37ad4856ddf6 Mon Sep 17 00:00:00 2001 From: mohammad Date: Wed, 30 Oct 2024 09:47:18 +0300 Subject: [PATCH 25/26] forget_password&power_clamp_issue --- lib/pages/auth/bloc/auth_bloc.dart | 42 +++++++++++++------ .../power_clamp/bloc/smart_power_bloc.dart | 7 ++-- .../view/smart_power_device_control.dart | 4 +- lib/services/auth_api.dart | 3 +- lib/utils/color_manager.dart | 3 +- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/lib/pages/auth/bloc/auth_bloc.dart b/lib/pages/auth/bloc/auth_bloc.dart index 5b269141..60cc2f86 100644 --- a/lib/pages/auth/bloc/auth_bloc.dart +++ b/lib/pages/auth/bloc/auth_bloc.dart @@ -31,7 +31,8 @@ class AuthBloc extends Bloc { ////////////////////////////// forget password ////////////////////////////////// final TextEditingController forgetEmailController = TextEditingController(); - final TextEditingController forgetPasswordController = TextEditingController(); + final TextEditingController forgetPasswordController = + TextEditingController(); final TextEditingController forgetOtp = TextEditingController(); final forgetFormKey = GlobalKey(); final forgetEmailKey = GlobalKey(); @@ -48,7 +49,8 @@ class AuthBloc extends Bloc { return; } _remainingTime = 1; - add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false)); + add(UpdateTimerEvent( + remainingTime: _remainingTime, isButtonEnabled: false)); try { forgetEmailValidate = ''; _remainingTime = (await AuthenticationAPI.sendOtp( @@ -84,7 +86,8 @@ class AuthBloc extends Bloc { _timer?.cancel(); add(const UpdateTimerEvent(remainingTime: 0, isButtonEnabled: true)); } else { - add(UpdateTimerEvent(remainingTime: _remainingTime, isButtonEnabled: false)); + add(UpdateTimerEvent( + remainingTime: _remainingTime, isButtonEnabled: false)); } }); } @@ -94,21 +97,25 @@ class AuthBloc extends Bloc { emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); } - Future changePassword(ChangePasswordEvent event, Emitter emit) async { + Future changePassword( + ChangePasswordEvent event, Emitter emit) async { emit(LoadingForgetState()); try { var response = await AuthenticationAPI.verifyOtp( email: forgetEmailController.text, otpCode: forgetOtp.text); if (response == true) { await AuthenticationAPI.forgetPassword( - password: forgetPasswordController.text, email: forgetEmailController.text); + otpCode: forgetOtp.text, + password: forgetPasswordController.text, + email: forgetEmailController.text); _timer?.cancel(); emit(const TimerState(isButtonEnabled: true, remainingTime: 0)); emit(SuccessForgetState()); } } on DioException catch (e) { final errorData = e.response!.data; - String errorMessage = errorData['error']['message'] ?? 'something went wrong'; + String errorMessage = + errorData['error']['message'] ?? 'something went wrong'; validate = errorMessage; emit(AuthInitialState()); } @@ -122,7 +129,9 @@ class AuthBloc extends Bloc { } void _onUpdateTimer(UpdateTimerEvent event, Emitter emit) { - emit(TimerState(isButtonEnabled: event.isButtonEnabled, remainingTime: event.remainingTime)); + emit(TimerState( + isButtonEnabled: event.isButtonEnabled, + remainingTime: event.remainingTime)); } ///////////////////////////////////// login ///////////////////////////////////// @@ -154,7 +163,9 @@ class AuthBloc extends Bloc { token = await AuthenticationAPI.loginWithEmail( model: LoginWithEmailModel( - email: event.username, password: event.password, regionUuid: event.regionUuid), + email: event.username, + password: event.password, + regionUuid: event.regionUuid), ); } catch (failure) { validate = 'Invalid Credentials!'; @@ -164,7 +175,8 @@ class AuthBloc extends Bloc { if (token.accessTokenIsNotEmpty) { FlutterSecureStorage storage = const FlutterSecureStorage(); - await storage.write(key: Token.loginAccessTokenKey, value: token.accessToken); + await storage.write( + key: Token.loginAccessTokenKey, value: token.accessToken); const FlutterSecureStorage().write( key: UserModel.userUuidKey, value: Token.decodeToken(token.accessToken)['uuid'].toString()); @@ -322,12 +334,14 @@ class AuthBloc extends Bloc { static Future getTokenAndValidate() async { try { const storage = FlutterSecureStorage(); - final firstLaunch = - await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true; + final firstLaunch = await SharedPreferencesHelper.readBoolFromSP( + StringsManager.firstLaunch) ?? + true; if (firstLaunch) { storage.deleteAll(); } - await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false); + await SharedPreferencesHelper.saveBoolToSP( + StringsManager.firstLaunch, false); final value = await storage.read(key: Token.loginAccessTokenKey) ?? ''; if (value.isEmpty) { return 'Token not found'; @@ -380,7 +394,9 @@ class AuthBloc extends Bloc { final String formattedTime = [ if (days > 0) '${days}d', // Append 'd' for days if (days > 0 || hours > 0) - hours.toString().padLeft(2, '0'), // Show hours if there are days or hours + hours + .toString() + .padLeft(2, '0'), // Show hours if there are days or hours minutes.toString().padLeft(2, '0'), seconds.toString().padLeft(2, '0'), ].join(':'); 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 04cb1b54..6792027f 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 @@ -589,14 +589,14 @@ class SmartPowerBloc extends Bloc { TextButton( child: const Text('Cancel'), onPressed: () { - Navigator.of(context) .pop(); + Navigator.of(context).pop(); }, ), TextButton( child: const Text('OK'), onPressed: () { final selectedDateTime = DateTime(selectedYear); - Navigator.of(context).pop(selectedDateTime); + Navigator.of(context).pop(selectedDateTime); }, ), ], @@ -718,7 +718,6 @@ class SmartPowerBloc extends Bloc { // formattedDate = newDate.toString(); }); emit(FilterRecordsState(filteredRecords: energyDataList)); - } List energyDataList = []; @@ -773,7 +772,7 @@ class SmartPowerBloc extends Bloc { } String endChartDate = ''; - + void selectDateRange() async { DateTime startDate = dateTime!; DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1) 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 635f44ea..0c55dcad 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 @@ -66,7 +66,7 @@ class SmartPowerDeviceControl extends StatelessWidget style: TextStyle( fontSize: 32, fontWeight: FontWeight.w700, - color: ColorsManager.grayColor), + color: ColorsManager.textPrimaryColor), ), ], ), @@ -176,7 +176,7 @@ class SmartPowerDeviceControl extends StatelessWidget children: [ EnergyConsumptionPage( formattedDate: - '${blocProvider.formattedDate}${blocProvider.endChartDate}', + '${blocProvider.dateTime!.day}/${blocProvider.dateTime!.month}/${blocProvider.dateTime!.year} ${blocProvider.endChartDate}', onTap: () { blocProvider.add(SelectDateEvent(context: context)); blocProvider.add(FilterRecordsByDateEvent( diff --git a/lib/services/auth_api.dart b/lib/services/auth_api.dart index f84bed1a..2b158cdb 100644 --- a/lib/services/auth_api.dart +++ b/lib/services/auth_api.dart @@ -18,10 +18,11 @@ class AuthenticationAPI { static Future forgetPassword({ required var email, required var password, + required var otpCode, }) async { final response = await HTTPService().post( path: ApiEndpoints.forgetPassword, - body: {"email": email, "password": password}, + body: {"email": email, "password": password,"otpCode": otpCode}, showServerMessage: true, expectedResponseModel: (json) {}); return response; diff --git a/lib/utils/color_manager.dart b/lib/utils/color_manager.dart index 9b4692bc..481fb2fa 100644 --- a/lib/utils/color_manager.dart +++ b/lib/utils/color_manager.dart @@ -42,4 +42,5 @@ abstract class ColorsManager { static const Color textGreen = Color(0xFF008905); static const Color yaGreen = Color(0xFFFFBF44); } -//background: #999999; +//background: #background: #5D5D5D; + From 8b1099c6832a209dca6a5a5a1f12b34ac5de230b Mon Sep 17 00:00:00 2001 From: mohammad Date: Wed, 30 Oct 2024 13:17:46 +0300 Subject: [PATCH 26/26] dateTime issue --- .../power_clamp/bloc/smart_power_bloc.dart | 318 +++++++++++++----- .../power_clamp/view/power_chart.dart | 8 +- .../view/smart_power_device_control.dart | 11 +- 3 files changed, 254 insertions(+), 83 deletions(-) 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 3928fb51..52cccff4 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 @@ -33,56 +33,190 @@ class SmartPowerBloc extends Bloc { int currentPage = 0; List record = [ - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:43'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:35'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:29'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:25'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:21'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:17'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:15:07'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:47'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:40'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:23'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2024-10-23 11:14:13'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:43'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:35'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:29'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:25'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:21'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:17'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:15:07'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:47'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:40'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:23'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-10-23 11:14:13'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:43'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:35'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:29'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:25'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:21'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:17'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:15:07'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:47'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:40'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:23'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-23 11:14:13'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-11 11:15:43'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-11 11:15:35'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-12 11:15:29'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-13 11:15:25'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-14 11:15:21'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-15 11:15:17'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-16 11:15:07'), value: '2286'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-17 11:14:47'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-18 11:14:40'), value: '2284'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-19 11:14:23'), value: '2285'), - EventDevice(code: 'VoltageA', eventTime: DateTime.parse('2023-02-20 11:14:13'), value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2024-10-23 11:14:13'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-10-23 11:14:13'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-23 11:14:13'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-11 11:15:43'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-11 11:15:35'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-12 11:15:29'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-13 11:15:25'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-14 11:15:21'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-15 11:15:17'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-16 11:15:07'), + value: '2286'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-17 11:14:47'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-18 11:14:40'), + value: '2284'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-19 11:14:23'), + value: '2285'), + EventDevice( + code: 'VoltageA', + eventTime: DateTime.parse('2023-02-20 11:14:13'), + value: '2284'), ]; - FutureOr _onFetchDeviceStatus(SmartPowerFetchDeviceEvent event, Emitter emit) async { + FutureOr _onFetchDeviceStatus( + SmartPowerFetchDeviceEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - var status = await DevicesManagementApi().getPowerClampInfo(event.deviceId); + var status = + await DevicesManagementApi().getPowerClampInfo(event.deviceId); deviceStatus = PowerClampModel.fromJson(status); phaseData = [ @@ -114,19 +248,22 @@ class SmartPowerBloc extends Bloc { } } - FutureOr _onArrowPressed(SmartPowerArrowPressedEvent event, Emitter emit) { + FutureOr _onArrowPressed( + SmartPowerArrowPressedEvent event, Emitter emit) { currentPage = (currentPage + event.direction + 4) % 4; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); emit(GetDeviceStatus()); } - FutureOr _onPageChanged(SmartPowerPageChangedEvent event, Emitter emit) { + FutureOr _onPageChanged( + SmartPowerPageChangedEvent event, Emitter emit) { currentPage = event.page; emit(SmartPowerStatusLoaded(deviceStatus, currentPage)); emit(GetDeviceStatus()); } - Future _onFactoryReset(SmartPowerFactoryReset event, Emitter emit) async { + Future _onFactoryReset( + SmartPowerFactoryReset event, Emitter emit) async { emit(SmartPowerLoading()); try { final response = await DevicesManagementApi().factoryReset( @@ -143,7 +280,8 @@ class SmartPowerBloc extends Bloc { } } - Future _onBatchControl(PowerBatchControlEvent event, Emitter emit) async { + Future _onBatchControl( + PowerBatchControlEvent event, Emitter emit) async { final oldValue = deviceStatus.status; _updateLocalValue(event.code, event.value); @@ -159,11 +297,14 @@ class SmartPowerBloc extends Bloc { ); } - Future _onFetchBatchStatus(SmartPowerFetchBatchEvent event, Emitter emit) async { + Future _onFetchBatchStatus( + SmartPowerFetchBatchEvent event, Emitter emit) async { emit(SmartPowerLoading()); try { - final response = await DevicesManagementApi().getPowerStatus(event.devicesIds); - PowerClampBatchModel deviceStatus = PowerClampBatchModel.fromJson(response); + final response = + await DevicesManagementApi().getPowerStatus(event.devicesIds); + PowerClampBatchModel deviceStatus = + PowerClampBatchModel.fromJson(response); emit(SmartPowerLoadBatchControll(deviceStatus)); } catch (e) { @@ -195,9 +336,11 @@ class SmartPowerBloc extends Bloc { try { late bool response; if (isBatch) { - response = await DevicesManagementApi().deviceBatchControl(deviceId, code, value); + response = await DevicesManagementApi() + .deviceBatchControl(deviceId, code, value); } else { - response = await DevicesManagementApi().deviceControl(deviceId, Status(code: code, value: value)); + response = await DevicesManagementApi() + .deviceControl(deviceId, Status(code: code, value: value)); } if (!response) { @@ -217,7 +360,8 @@ class SmartPowerBloc extends Bloc { } } - void _revertValueAndEmit(String deviceId, String code, dynamic oldValue, Emitter emit) { + void _revertValueAndEmit(String deviceId, String code, dynamic oldValue, + Emitter emit) { _updateLocalValue(code, oldValue); emit(SmartPowerLoadBatchControll(deviceBatchStatus)); } @@ -274,8 +418,10 @@ class SmartPowerBloc extends Bloc { int selectedYear = DateTime.now().year; int selectedMonth = DateTime.now().month; - FixedExtentScrollController yearController = FixedExtentScrollController(initialItem: selectedYear - 1905); - FixedExtentScrollController monthController = FixedExtentScrollController(initialItem: selectedMonth - 1); + FixedExtentScrollController yearController = + FixedExtentScrollController(initialItem: selectedYear - 1905); + FixedExtentScrollController monthController = + FixedExtentScrollController(initialItem: selectedMonth - 1); return await showDialog( context: context, @@ -285,7 +431,10 @@ class SmartPowerBloc extends Bloc { mainAxisAlignment: MainAxisAlignment.center, children: [ Container( - color: Colors.white, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + ), height: 350, width: 350, child: Column( @@ -294,7 +443,8 @@ class SmartPowerBloc extends Bloc { padding: EdgeInsets.all(16.0), child: Text( 'Select Month and Year', - style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + style: + TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), ), const Divider(), @@ -337,7 +487,8 @@ class SmartPowerBloc extends Bloc { builder: (context, index) { return Center( child: Text( - DateFormat.MMMM().format(DateTime(0, index + 1)), + DateFormat.MMMM() + .format(DateTime(0, index + 1)), style: const TextStyle(fontSize: 18), ), ); @@ -352,7 +503,8 @@ class SmartPowerBloc extends Bloc { ), const Divider(), Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), + padding: const EdgeInsets.symmetric( + horizontal: 16.0, vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -365,7 +517,8 @@ class SmartPowerBloc extends Bloc { TextButton( child: const Text('OK'), onPressed: () { - final selectedDateTime = DateTime(selectedYear, selectedMonth); + final selectedDateTime = + DateTime(selectedYear, selectedMonth); Navigator.of(context).pop(selectedDateTime); }, ), @@ -383,7 +536,8 @@ class SmartPowerBloc extends Bloc { Future selectYear(BuildContext context) async { int selectedYear = DateTime.now().year; - FixedExtentScrollController yearController = FixedExtentScrollController(initialItem: selectedYear - 1905); + FixedExtentScrollController yearController = + FixedExtentScrollController(initialItem: selectedYear - 1905); return await showDialog( context: context, @@ -393,7 +547,10 @@ class SmartPowerBloc extends Bloc { mainAxisAlignment: MainAxisAlignment.center, children: [ Container( - color: Colors.white, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10), + ), height: 350, width: 350, child: Column( @@ -402,7 +559,8 @@ class SmartPowerBloc extends Bloc { padding: EdgeInsets.all(16.0), child: Text( 'Select Year', - style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), + style: + TextStyle(fontSize: 20, fontWeight: FontWeight.bold), ), ), const Divider(), @@ -429,7 +587,8 @@ class SmartPowerBloc extends Bloc { ), const Divider(), Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), + padding: const EdgeInsets.symmetric( + horizontal: 16.0, vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -492,7 +651,8 @@ class SmartPowerBloc extends Bloc { ), const Divider(), Padding( - padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0), + padding: const EdgeInsets.symmetric( + horizontal: 16.0, vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -524,7 +684,8 @@ class SmartPowerBloc extends Bloc { String formattedDate = DateFormat('yyyy/MM/dd').format(DateTime.now()); - void checkDayMonthYearSelected(SelectDateEvent event, Emitter emit) async { + void checkDayMonthYearSelected( + SelectDateEvent event, Emitter emit) async { Future Function(BuildContext context)? dateSelector; String dateFormat; switch (currentIndex) { @@ -569,18 +730,23 @@ class SmartPowerBloc extends Bloc { } List energyDataList = []; - void _filterRecordsByDate(FilterRecordsByDateEvent event, Emitter emit) { + void _filterRecordsByDate( + FilterRecordsByDateEvent event, Emitter emit) { // emit(SmartPowerLoading()); if (event.viewType == 'Year') { formattedDate = event.selectedDate.year.toString(); - filteredRecords = record.where((record) => record.eventTime!.year == event.selectedDate.year).toList(); + 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)}"; + 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) + record.eventTime!.year == event.selectedDate.year && + record.eventTime!.month == event.selectedDate.month) .toList(); } else if (event.viewType == 'Day') { formattedDate = @@ -598,7 +764,8 @@ class SmartPowerBloc extends Bloc { energyDataList = filteredRecords.map((eventDevice) { return EnergyData( event.viewType == 'Year' - ? getMonthShortName(int.tryParse(DateFormat('MM').format(eventDevice.eventTime!))!) + ? getMonthShortName( + int.tryParse(DateFormat('MM').format(eventDevice.eventTime!))!) : event.viewType == 'Month' ? DateFormat('yyyy/MM/dd').format(eventDevice.eventTime!) : DateFormat('HH:mm:ss').format(eventDevice.eventTime!), @@ -617,7 +784,8 @@ class SmartPowerBloc extends Bloc { void selectDateRange() async { DateTime startDate = dateTime!; - DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1).subtract(Duration(days: 1)); + 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/view/power_chart.dart b/lib/pages/device_managment/power_clamp/view/power_chart.dart index 273537ba..19050b8a 100644 --- a/lib/pages/device_managment/power_clamp/view/power_chart.dart +++ b/lib/pages/device_managment/power_clamp/view/power_chart.dart @@ -93,9 +93,9 @@ class _EnergyConsumptionPageState extends State { Column( children: [ Padding( - padding: const EdgeInsets.only(top: 15), + padding: const EdgeInsets.only(top: 10), child: SizedBox( - height: MediaQuery.of(context).size.height * 0.12, + height: MediaQuery.of(context).size.height * 0.11, child: LineChart( LineChartData( lineTouchData: LineTouchData( @@ -227,7 +227,7 @@ class _EnergyConsumptionPageState extends State { ), ), Padding( - padding: const EdgeInsets.all(8.0), + padding: const EdgeInsets.all(5.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -240,7 +240,7 @@ class _EnergyConsumptionPageState extends State { child: Container(child: widget.widget), ), ), - SizedBox( + const SizedBox( width: 20, ), Expanded( 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 2b16946f..03d649fa 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 @@ -172,9 +172,10 @@ class SmartPowerDeviceControl extends StatelessWidget ), ), const SizedBox( - height: 10, + height: 5, ), Expanded( + flex: 2, child: PageView( controller: _pageController, onPageChanged: (int page) { @@ -184,7 +185,7 @@ class SmartPowerDeviceControl extends StatelessWidget children: [ EnergyConsumptionPage( formattedDate: - '${blocProvider.formattedDate}${blocProvider.endChartDate}', + '${blocProvider.dateTime!.day}/${blocProvider.dateTime!.month}/${blocProvider.dateTime!.year} ${blocProvider.endChartDate}', onTap: () { blocProvider.add(SelectDateEvent(context: context)); blocProvider.add(FilterRecordsByDateEvent( @@ -213,7 +214,8 @@ class SmartPowerDeviceControl extends StatelessWidget date: blocProvider.formattedDate, ), EnergyConsumptionPage( - formattedDate: blocProvider.formattedDate, + formattedDate: + '${blocProvider.dateTime!.day}/${blocProvider.dateTime!.month}/${blocProvider.dateTime!.year} ${blocProvider.endChartDate}', onTap: () { blocProvider.add(SelectDateEvent(context: context)); }, @@ -238,7 +240,8 @@ class SmartPowerDeviceControl extends StatelessWidget date: blocProvider.formattedDate, ), EnergyConsumptionPage( - formattedDate: blocProvider.formattedDate, + formattedDate: + '${blocProvider.dateTime!.day}/${blocProvider.dateTime!.month}/${blocProvider.dateTime!.year} ${blocProvider.endChartDate}', onTap: () { blocProvider.add(SelectDateEvent(context: context)); },