From 9e5d5c0d842d85baf7c72065ce32f6b81c1b9a00 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Tue, 1 Oct 2024 00:27:03 +0300 Subject: [PATCH] push bug fixes --- lib/pages/common/buttons/default_button.dart | 10 +- .../ac/view/ac_device_batch_control.dart | 2 +- .../ac/view/ac_device_control.dart | 18 ++- .../widgets/device_managment_body.dart | 54 +++++--- .../gateway/view/gateway_view.dart | 4 +- .../view/main_door_control_view.dart | 4 +- .../shared/batch_control/factory_reset.dart | 122 ++++++++++++++---- .../shared/device_control_dialog.dart | 23 +++- .../water_heater/bloc/water_heater_bloc.dart | 1 + .../water_heater/bloc/water_heater_event.dart | 2 +- .../water_heater/bloc/water_heater_state.dart | 2 +- .../helper/add_schedule_dialog_helper.dart | 7 +- .../view/water_heater_device_control.dart | 1 + .../water_heater/widgets/schedual_view.dart | 13 +- .../water_heater/widgets/schedule_table.dart | 2 +- 15 files changed, 192 insertions(+), 73 deletions(-) diff --git a/lib/pages/common/buttons/default_button.dart b/lib/pages/common/buttons/default_button.dart index 4ff89d74..8c391ecb 100644 --- a/lib/pages/common/buttons/default_button.dart +++ b/lib/pages/common/buttons/default_button.dart @@ -18,6 +18,7 @@ class DefaultButton extends StatelessWidget { this.height, this.padding, this.borderColor, + this.elevation, }); final void Function()? onPressed; final Widget child; @@ -33,6 +34,7 @@ class DefaultButton extends StatelessWidget { final Color? backgroundColor; final Color? foregroundColor; final Color? borderColor; + final double? elevation; @override Widget build(BuildContext context) { @@ -45,7 +47,9 @@ class DefaultButton extends StatelessWidget { textStyle: WidgetStateProperty.all( customTextStyle ?? Theme.of(context).textTheme.bodySmall!.copyWith( - fontSize: 13, color: foregroundColor, fontWeight: FontWeight.normal), + fontSize: 13, + color: foregroundColor, + fontWeight: FontWeight.normal), ), foregroundColor: WidgetStateProperty.all( isSecondary @@ -54,7 +58,8 @@ class DefaultButton extends StatelessWidget { ? foregroundColor ?? Colors.white : Colors.black, ), - backgroundColor: WidgetStateProperty.resolveWith((Set states) { + backgroundColor: WidgetStateProperty.resolveWith( + (Set states) { return enabled ? backgroundColor ?? ColorsManager.primaryColor : Colors.black.withOpacity(0.2); @@ -74,6 +79,7 @@ class DefaultButton extends StatelessWidget { minimumSize: WidgetStateProperty.all( const Size.fromHeight(50), ), + elevation: WidgetStateProperty.all(elevation ?? 0), ), child: SizedBox( height: height ?? 50, diff --git a/lib/pages/device_managment/ac/view/ac_device_batch_control.dart b/lib/pages/device_managment/ac/view/ac_device_batch_control.dart index 9331072d..94edf837 100644 --- a/lib/pages/device_managment/ac/view/ac_device_batch_control.dart +++ b/lib/pages/device_managment/ac/view/ac_device_batch_control.dart @@ -46,11 +46,11 @@ class AcDeviceBatchControlView extends StatelessWidget ), children: [ ToggleWidget( - icon: Assets.acLock, deviceId: devicesIds.first, code: 'switch', value: state.status.acSwitch, label: 'ThermoState', + icon: Assets.ac, onChange: (value) { context.read().add(AcBatchControlEvent( devicesIds: devicesIds, 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 2283f6ad..c69583ae 100644 --- a/lib/pages/device_managment/ac/view/ac_device_control.dart +++ b/lib/pages/device_managment/ac/view/ac_device_control.dart @@ -8,6 +8,7 @@ import 'package:syncrow_web/pages/device_managment/ac/view/control_list/ac_toggl import 'package:syncrow_web/pages/device_managment/ac/view/control_list/current_temp.dart'; import 'package:syncrow_web/pages/device_managment/ac/view/control_list/fan_speed.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; +import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; @@ -64,12 +65,21 @@ class AcDeviceControlsView extends StatelessWidget with HelperResponsiveLayout { code: 'level', deviceId: device.uuid!, ), - AcToggle( - value: state.status.childLock, - code: 'child_lock', + ToggleWidget( deviceId: device.uuid!, - description: 'Child Lock', + code: 'child_lock', + value: state.status.childLock, + label: 'Child Lock', icon: state.status.childLock ? Assets.unlock : Assets.acLock, + onChange: (value) { + context.read().add( + AcControlEvent( + deviceId: device.uuid!, + code: 'child_lock', + value: value, + ), + ); + }, ), ], ); 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 55e4e291..46dc5bbd 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 @@ -37,8 +37,8 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { offlineCount = state.offlineCount; lowBatteryCount = state.lowBatteryCount; isControlButtonEnabled = state.isControlButtonEnabled; - selectedDevices = - state.selectedDevice ?? context.read().selectedDevices; + selectedDevices = state.selectedDevice ?? + context.read().selectedDevices; } else if (state is DeviceManagementFiltered) { devicesToShow = state.filteredDevices; selectedIndex = state.selectedIndex; @@ -46,8 +46,8 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { offlineCount = state.offlineCount; lowBatteryCount = state.lowBatteryCount; isControlButtonEnabled = state.isControlButtonEnabled; - selectedDevices = - state.selectedDevice ?? context.read().selectedDevices; + selectedDevices = state.selectedDevice ?? + context.read().selectedDevices; } else if (state is DeviceManagementInitial) { devicesToShow = []; selectedIndex = 0; @@ -61,13 +61,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: [ @@ -76,7 +78,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), @@ -98,12 +102,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, ), ); @@ -117,7 +123,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, ), ), ), @@ -136,7 +144,9 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { cellDecoration: containerDecoration, onRowSelected: (index, isSelected, row) { final selectedDevice = devicesToShow[index]; - context.read().add(SelectDevice(selectedDevice)); + context + .read() + .add(SelectDevice(selectedDevice)); }, withCheckBox: true, size: context.screenSize, @@ -154,21 +164,25 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { ], data: devicesToShow.map((device) { return [ - device.categoryName ?? '', device.name ?? '', + device.categoryName ?? '', 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() diff --git a/lib/pages/device_managment/gateway/view/gateway_view.dart b/lib/pages/device_managment/gateway/view/gateway_view.dart index ad760a14..f6cc4682 100644 --- a/lib/pages/device_managment/gateway/view/gateway_view.dart +++ b/lib/pages/device_managment/gateway/view/gateway_view.dart @@ -70,8 +70,8 @@ class _DeviceItem extends StatelessWidget { Container( width: 60, height: 60, - decoration: const BoxDecoration( - shape: BoxShape.circle, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(100), color: ColorsManager.whiteColors, ), margin: const EdgeInsets.symmetric(horizontal: 4), diff --git a/lib/pages/device_managment/main_door_sensor/view/main_door_control_view.dart b/lib/pages/device_managment/main_door_sensor/view/main_door_control_view.dart index 44b2fec3..5785a799 100644 --- a/lib/pages/device_managment/main_door_sensor/view/main_door_control_view.dart +++ b/lib/pages/device_managment/main_door_sensor/view/main_door_control_view.dart @@ -80,7 +80,9 @@ class MainDoorSensorControlView extends StatelessWidget icon: Assets.openCloseDoor, onTap: () {}, status: status.doorContactState, - textColor: ColorsManager.red, + textColor: status.doorContactState + ? ColorsManager.red + : ColorsManager.blackColor, paddingAmount: 8, ), IconNameStatusContainer( 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 78dfc307..3153cd48 100644 --- a/lib/pages/device_managment/shared/batch_control/factory_reset.dart +++ b/lib/pages/device_managment/shared/batch_control/factory_reset.dart @@ -1,47 +1,113 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:syncrow_web/pages/common/buttons/default_button.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/extension/build_context_x.dart'; -class FactoryResetWidget extends StatelessWidget { +class FactoryResetWidget extends StatefulWidget { const FactoryResetWidget({super.key, required this.callFactoryReset}); - final Null Function() callFactoryReset; + final Function() callFactoryReset; + + @override + State createState() => _FactoryResetWidgetState(); +} + +class _FactoryResetWidgetState extends State { + bool _showConfirmation = false; + + void _toggleConfirmation() { + setState(() { + _showConfirmation = !_showConfirmation; + }); + } @override Widget build(BuildContext context) { return DeviceControlsContainer( - child: GestureDetector( - onTap: callFactoryReset, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ClipOval( - child: Container( - color: ColorsManager.whiteColors, - height: 60, - width: 60, - child: Padding( - padding: const EdgeInsets.all(12.0), - child: SvgPicture.asset( - Assets.factoryReset, - fit: BoxFit.cover, + child: _showConfirmation + ? Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + 'Factory Reset', + style: context.textTheme.titleMedium!.copyWith( + fontWeight: FontWeight.bold, + color: ColorsManager.blackColor, + ), ), - ), - )), - Text( - 'Factory Reset', - style: context.textTheme.titleMedium!.copyWith( - fontWeight: FontWeight.w400, - color: ColorsManager.blackColor, + Text( + 'Are you sure?', + style: context.textTheme.bodySmall!.copyWith( + color: ColorsManager.grayColor, + ), + ), + const SizedBox(height: 16), + Row( + children: [ + Flexible( + child: DefaultButton( + height: 20, + elevation: 0, + onPressed: _toggleConfirmation, + backgroundColor: ColorsManager.greyColor, + child: Text( + 'Cancel', + style: context.textTheme.bodyMedium, + ), + ), + ), + const SizedBox(width: 8), + Flexible( + child: DefaultButton( + height: 20, + elevation: 0, + onPressed: widget.callFactoryReset, + backgroundColor: ColorsManager.red, + child: Text( + 'Reset', + style: context.textTheme.bodyMedium! + .copyWith(color: ColorsManager.whiteColors), + ), + ), + ), + ], + ), + ], + ) + : GestureDetector( + onTap: _toggleConfirmation, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ClipOval( + child: Container( + color: ColorsManager.whiteColors, + height: 60, + width: 60, + child: Padding( + padding: const EdgeInsets.all(12.0), + child: SvgPicture.asset( + Assets.factoryReset, + fit: BoxFit.cover, + ), + ), + ), + ), + Text( + 'Factory Reset', + style: context.textTheme.titleMedium!.copyWith( + fontWeight: FontWeight.w400, + color: ColorsManager.blackColor, + ), + ), + ], ), ), - ], - ), - ), ); } } diff --git a/lib/pages/device_managment/shared/device_control_dialog.dart b/lib/pages/device_managment/shared/device_control_dialog.dart index f69c7c83..acf1578c 100644 --- a/lib/pages/device_managment/shared/device_control_dialog.dart +++ b/lib/pages/device_managment/shared/device_control_dialog.dart @@ -92,7 +92,7 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode { ], ), TableRow(children: [ - _buildInfoRow('Virtual Address:', '${device.ip}'), + _buildInfoRow('Virtual Address:', device.ip ?? '-'), const SizedBox.shrink(), ]), TableRow( @@ -111,13 +111,30 @@ class DeviceControlDialog extends StatelessWidget with RouteControlsBasedCode { ), ), ), - const SizedBox.shrink(), + _buildInfoRow( + 'Battery Level:', + device.batteryLevel != null + ? '${device.batteryLevel ?? 0}%' + : "-", + statusColor: device.batteryLevel != null + ? (device.batteryLevel! < 20 + ? ColorsManager.red + : ColorsManager.green) + : null, + ), ], ), TableRow( children: [ _buildInfoRow('Status:', 'Online', statusColor: Colors.green), - _buildInfoRow('Last Offline Date and Time:', '-'), + _buildInfoRow( + 'Last Offline Date and Time:', + formatDateTime( + DateTime.fromMillisecondsSinceEpoch( + ((device.activeTime ?? 0) * 1000), + ), + ), + ), ], ), ], diff --git a/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart b/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart index 9d24eb12..023faa7a 100644 --- a/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart +++ b/lib/pages/device_managment/water_heater/bloc/water_heater_bloc.dart @@ -65,6 +65,7 @@ class WaterHeaterBloc extends Bloc { Emitter emit, ) { final currentState = state as WaterHeaterDeviceStatusLoaded; + emit(currentState.copyWith(selectedTime: event.selectedTime)); } diff --git a/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart b/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart index d723f709..4b9ec7a1 100644 --- a/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart +++ b/lib/pages/device_managment/water_heater/bloc/water_heater_event.dart @@ -130,7 +130,7 @@ class InitializeAddScheduleEvent extends WaterHeaterEvent { } class UpdateSelectedTimeEvent extends WaterHeaterEvent { - final TimeOfDay selectedTime; + final TimeOfDay? selectedTime; const UpdateSelectedTimeEvent(this.selectedTime); diff --git a/lib/pages/device_managment/water_heater/bloc/water_heater_state.dart b/lib/pages/device_managment/water_heater/bloc/water_heater_state.dart index 5ff5ba3d..c2df43c3 100644 --- a/lib/pages/device_managment/water_heater/bloc/water_heater_state.dart +++ b/lib/pages/device_managment/water_heater/bloc/water_heater_state.dart @@ -99,7 +99,7 @@ class WaterHeaterDeviceStatusLoaded extends WaterHeaterState { isInchingActive: isInchingActive ?? this.isInchingActive, schedules: schedules ?? this.schedules, selectedDays: selectedDays ?? this.selectedDays, - selectedTime: selectedTime ?? this.selectedTime, + selectedTime: selectedTime, functionOn: functionOn ?? this.functionOn, isEditing: isEditing ?? this.isEditing, ); diff --git a/lib/pages/device_managment/water_heater/helper/add_schedule_dialog_helper.dart b/lib/pages/device_managment/water_heater/helper/add_schedule_dialog_helper.dart index 28a0fc32..4ccec509 100644 --- a/lib/pages/device_managment/water_heater/helper/add_schedule_dialog_helper.dart +++ b/lib/pages/device_managment/water_heater/helper/add_schedule_dialog_helper.dart @@ -12,6 +12,7 @@ class ScheduleDialogHelper { final bloc = context.read(); if (schedule == null) { + bloc.add((const UpdateSelectedTimeEvent(null))); bloc.add(InitializeAddScheduleEvent( selectedTime: null, selectedDays: List.filled(7, false), @@ -95,7 +96,7 @@ class ScheduleDialogHelper { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - state.selectedTime == null || schedule == null + state.selectedTime == null ? 'Time' : state.selectedTime!.format(context), style: context.textTheme.bodySmall!.copyWith( @@ -180,7 +181,7 @@ class ScheduleDialogHelper { } static List _convertDaysStringToBooleans(List selectedDays) { - final daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; + final daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; List daysBoolean = List.filled(7, false); for (int i = 0; i < daysOfWeek.length; i++) { @@ -195,7 +196,7 @@ class ScheduleDialogHelper { static Widget _buildDayCheckboxes( BuildContext context, List selectedDays, {bool? isEdit}) { - final dayLabels = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; + final dayLabels = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; return Row( children: List.generate(7, (index) { diff --git a/lib/pages/device_managment/water_heater/view/water_heater_device_control.dart b/lib/pages/device_managment/water_heater/view/water_heater_device_control.dart index 57f7444d..40d3edb5 100644 --- a/lib/pages/device_managment/water_heater/view/water_heater_device_control.dart +++ b/lib/pages/device_managment/water_heater/view/water_heater_device_control.dart @@ -62,6 +62,7 @@ class WaterHeaterDeviceControlView extends StatelessWidget deviceId: device.uuid!, code: 'switch_1', value: status.heaterSwitch, + icon: Assets.waterHeater, label: 'Water Heater', onChange: (value) { context.read().add(ToggleWaterHeaterEvent( diff --git a/lib/pages/device_managment/water_heater/widgets/schedual_view.dart b/lib/pages/device_managment/water_heater/widgets/schedual_view.dart index 4febbaf5..9d4a2497 100644 --- a/lib/pages/device_managment/water_heater/widgets/schedual_view.dart +++ b/lib/pages/device_managment/water_heater/widgets/schedual_view.dart @@ -52,12 +52,13 @@ class _BuildScheduleViewState extends State { if (state.scheduleMode == ScheduleModes.schedule) ScheduleManagementUI( state: state, - onAddSchedule: () => - ScheduleDialogHelper.showAddScheduleDialog( - context, - schedule: null, - index: null, - isEdit: false), + onAddSchedule: () { + ScheduleDialogHelper.showAddScheduleDialog( + context, + schedule: null, + index: null, + isEdit: false); + }, ), if (state.scheduleMode == ScheduleModes.countdown || state.scheduleMode == ScheduleModes.inching) diff --git a/lib/pages/device_managment/water_heater/widgets/schedule_table.dart b/lib/pages/device_managment/water_heater/widgets/schedule_table.dart index c1694107..18cbbe5a 100644 --- a/lib/pages/device_managment/water_heater/widgets/schedule_table.dart +++ b/lib/pages/device_managment/water_heater/widgets/schedule_table.dart @@ -210,7 +210,7 @@ class ScheduleTableWidget extends StatelessWidget { } String _getSelectedDays(List selectedDays) { - final days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']; + final days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; List selectedDaysStr = []; for (int i = 0; i < selectedDays.length; i++) { if (selectedDays[i]) {