From f9a2de976946ba418f365aecbbb22f47d5e3c90d Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Mon, 1 Jul 2024 19:18:40 +0300 Subject: [PATCH 01/11] solved cancel issue --- .../bloc/create_scene/create_scene_bloc.dart | 6 +++ .../bloc/create_scene/create_scene_event.dart | 2 - .../helper/scene_operations_data_helper.dart | 8 ++++ .../scene/view/device_functions_view.dart | 44 ++++++++++++------- .../alert_dialog_functions_body.dart | 7 +-- .../scene/widgets/bottom_sheet_widget.dart | 28 ++++++------ .../if_then_containers/then_container.dart | 1 + 7 files changed, 60 insertions(+), 36 deletions(-) diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index 369a482..0c8fec8 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -87,12 +87,14 @@ class CreateSceneBloc extends Bloc } emit(TempHoldSceneTask(tempTasksList: tempTasksList)); + emit(AddSceneTask(tasksList: tasksList)); } FutureOr _selectedValue( SelectedValueEvent event, Emitter emit) { selectedValues[event.code] = event.value; emit(SelectedTaskValueState(value: event.value)); + emit(AddSceneTask(tasksList: tasksList)); } FutureOr _removeTaskById( @@ -116,6 +118,8 @@ class CreateSceneBloc extends Bloc tempTasksList.remove(element); emit(TempHoldSceneTask(tempTasksList: tempTasksList)); + emit(AddSceneTask(tasksList: tasksList)); + break; } } @@ -172,6 +176,7 @@ class CreateSceneBloc extends Bloc tempTasksList.clear(); selectedValues.clear(); emit(TempHoldSceneTask(tempTasksList: tempTasksList)); + emit(AddSceneTask(tasksList: tempTasksList)); } FutureOr _removeFromSelectedValueById( @@ -179,6 +184,7 @@ class CreateSceneBloc extends Bloc if (selectedValues.containsKey(event.code)) { selectedValues.remove(event.code); emit(const SelectedTaskValueState(value: null)); + emit(AddSceneTask(tasksList: tasksList)); } } diff --git a/lib/features/scene/bloc/create_scene/create_scene_event.dart b/lib/features/scene/bloc/create_scene/create_scene_event.dart index a5af5eb..79f72e1 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_event.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_event.dart @@ -8,8 +8,6 @@ sealed class CreateSceneEvent extends Equatable { } class AddTaskEvent extends CreateSceneEvent { - final bool updateTaskListFromTemp; - const AddTaskEvent({required this.updateTaskListFromTemp}); @override List get props => []; } diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index 0f0c1e8..c1e2079 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -660,6 +660,9 @@ mixin SceneOperationsDataHelper { ]; } +///////&************ END of get function with icons for device *************&&//////// + /// + /// List getTaskListFunctionsFromApi({ required List actions, required String deviceId, @@ -1267,6 +1270,11 @@ mixin SceneOperationsDataHelper { return functions; } + ///// END of get fucntion for once device based on the CODE ***** /////// + /// + /// + /// + List getOperationsForOneFunction({ required String deviceId, required SceneStaticFunction taskItem, diff --git a/lib/features/scene/view/device_functions_view.dart b/lib/features/scene/view/device_functions_view.dart index c43af8a..5ad9974 100644 --- a/lib/features/scene/view/device_functions_view.dart +++ b/lib/features/scene/view/device_functions_view.dart @@ -48,7 +48,7 @@ class DeviceFunctionsView extends StatelessWidget onPressed: () { context .read() - .add(const AddTaskEvent(updateTaskListFromTemp: true)); + .add( AddTaskEvent()); Navigator.popUntil(context, (route) { return route.settings.name == Routes.sceneTasksRoute; }); @@ -62,7 +62,19 @@ class DeviceFunctionsView extends StatelessWidget ], leading: TextButton( onPressed: () { - context.read().add(const ClearTaskListEvent()); + final selectedValue = + context.read().selectedValues; + for (var element in device.functions) { + if (selectedValue.containsKey(element.code)) { + context + .read() + .add(RemoveTempTaskByIdEvent(code: element.code!)); + context + .read() + .add(RemoveFromSelectedValueById(code: element.code!)); + } + } + Navigator.pop(context); }, child: BodyMedium( @@ -174,22 +186,22 @@ class DeviceFunctionsView extends StatelessWidget final tempTaskList = context .read() .tempTasksList; - if (tempTaskList.isEmpty) { - context - .read() - .add(const ClearTempTaskListEvent()); - } else { - for (var element in tempTaskList) { - if (element.code == functions[index].code) { - context.read().add( - RemoveTempTaskByIdEvent( - code: functions[index].code)); - context.read().add( - RemoveFromSelectedValueById( - code: functions[index].code)); - } + // if (tempTaskList.isEmpty) { + // context + // .read() + // .add(const ClearTempTaskListEvent()); + // } else { + for (var element in tempTaskList) { + if (element.code == functions[index].code) { + context.read().add( + RemoveTempTaskByIdEvent( + code: functions[index].code)); + context.read().add( + RemoveFromSelectedValueById( + code: functions[index].code)); } } + //} Navigator.pop(context); }, ); diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart index 7af1ec0..9c71ef5 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart @@ -29,9 +29,10 @@ class _AlertDialogFunctionsOperationsBodyState didChangeDependencies() { super.didChangeDependencies(); final tempTaskList = context.read().tempTasksList; - if (tempTaskList.isEmpty) { - context.read().add(const ClearTempTaskListEvent()); - } else if (tempTaskList.isNotEmpty) { + // if (tempTaskList.isEmpty) { + // context.read().add(const ClearTempTaskListEvent()); + // } else + if (tempTaskList.isNotEmpty) { for (var element in tempTaskList) { if (element.code == widget.functions[widget.index].code) { groupValue = element.functionValue; diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 7700fbb..872e1eb 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -124,27 +124,25 @@ class CustomBottomSheetWidget extends StatelessWidget { deviceName: 'Delay The Action', uniqueId: functions[0].uniqueCustomId, )); - context - .read() - .add(const AddTaskEvent(updateTaskListFromTemp: true)); + context.read().add(AddTaskEvent()); Navigator.pop(context); }, onDismiss: () { final tempTaskList = context.read().tempTasksList; - if (tempTaskList.isEmpty) { - context.read().add(const ClearTempTaskListEvent()); - } else { - for (var element in tempTaskList) { - if (element.code == functions[0].code) { - context - .read() - .add(RemoveTempTaskByIdEvent(code: functions[0].code)); - context - .read() - .add(RemoveFromSelectedValueById(code: functions[0].code)); - } + // if (tempTaskList.isNotEmpty) { + // context.read().add(const ClearTempTaskListEvent()); + // } else { + for (var element in tempTaskList) { + if (element.code == functions[0].code) { + context + .read() + .add(RemoveTempTaskByIdEvent(code: functions[0].code)); + context + .read() + .add(RemoveFromSelectedValueById(code: functions[0].code)); } } + // } Navigator.pop(context); }, ); diff --git a/lib/features/scene/widgets/if_then_containers/then_container.dart b/lib/features/scene/widgets/if_then_containers/then_container.dart index 47bc900..3c36709 100644 --- a/lib/features/scene/widgets/if_then_containers/then_container.dart +++ b/lib/features/scene/widgets/if_then_containers/then_container.dart @@ -55,6 +55,7 @@ class ThenDefaultContainer extends StatelessWidget { if (state is CreateSceneLoading) { return const Center(child: LinearProgressIndicator()); } + if (state is AddSceneTask) { final taskLists = state.tasksList; if (taskLists.isNotEmpty) { From 16a336ab094d3e22f00686eb9898558073c911ed Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Mon, 1 Jul 2024 20:05:05 +0300 Subject: [PATCH 02/11] fix load scenes after creation --- lib/features/scene/view/scene_view.dart | 6 ++++++ lib/features/scene/widgets/create_scene_save_button.dart | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/features/scene/view/scene_view.dart b/lib/features/scene/view/scene_view.dart index c991b4b..f6fb7fd 100644 --- a/lib/features/scene/view/scene_view.dart +++ b/lib/features/scene/view/scene_view.dart @@ -26,6 +26,12 @@ class SceneView extends StatelessWidget { .add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)); } } + if (state is CreateSceneWithTasks) { + if (state.success == true) { + BlocProvider.of(context) + .add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)); + } + } return BlocListener( listener: (context, state) { if (state is SceneTriggerSuccess) { diff --git a/lib/features/scene/widgets/create_scene_save_button.dart b/lib/features/scene/widgets/create_scene_save_button.dart index ee55909..29a0e9f 100644 --- a/lib/features/scene/widgets/create_scene_save_button.dart +++ b/lib/features/scene/widgets/create_scene_save_button.dart @@ -1,6 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; +import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart'; +import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart'; import 'package:syncrow_app/features/scene/helper/scene_logic_helper.dart'; import 'package:syncrow_app/features/shared_widgets/default_button.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; @@ -45,7 +48,6 @@ class _CreateSceneSaveButtonState extends State if (state.success == true) { Navigator.pop(context); Navigator.pop(context); - context.showCustomSnackbar( message: 'Scene created successfully', icon: const Icon( From 4b6d82812d5f0c949c6eb85e9ce78607a859def5 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Mon, 1 Jul 2024 20:16:00 +0300 Subject: [PATCH 03/11] fix delay format --- lib/features/scene/widgets/bottom_sheet_widget.dart | 2 +- lib/features/scene/widgets/create_scene_save_button.dart | 3 --- .../scene/widgets/if_then_containers/then_added_tasks.dart | 3 ++- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 872e1eb..887fa27 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -95,7 +95,7 @@ class CustomBottomSheetWidget extends StatelessWidget { deviceName: 'Delay The Action', icon: '', operationName: 'Delay The Action', - code: 'delay', + code: '', functionValue: 0, operationalValues: [ SceneOperationalValue(icon: '', value: 0), diff --git a/lib/features/scene/widgets/create_scene_save_button.dart b/lib/features/scene/widgets/create_scene_save_button.dart index 29a0e9f..179153d 100644 --- a/lib/features/scene/widgets/create_scene_save_button.dart +++ b/lib/features/scene/widgets/create_scene_save_button.dart @@ -1,9 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; -import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart'; -import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart'; import 'package:syncrow_app/features/scene/helper/scene_logic_helper.dart'; import 'package:syncrow_app/features/shared_widgets/default_button.dart'; import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart'; diff --git a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart index f5a99cd..c1870b1 100644 --- a/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart +++ b/lib/features/scene/widgets/if_then_containers/then_added_tasks.dart @@ -33,7 +33,8 @@ class ThenAddedTasksContainer extends StatelessWidget @override Widget build(BuildContext context) { String operationValue = ''; - if (taskItem.code.contains('countdown')) { + if (taskItem.code.contains('countdown') || + taskItem.deviceId.contains('delay')) { final functionValue = taskItem.functionValue ?? taskItem.operationalValues.first.value; final duration = From bf05f945860c019a9db8a41726f6e416e5938c71 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Mon, 1 Jul 2024 20:51:14 +0300 Subject: [PATCH 04/11] finished sending the delay in correct way --- lib/features/scene/helper/scene_logic_helper.dart | 10 ++++++---- .../widgets/alert_dialogs/alert_dialog_countdown.dart | 4 ++-- lib/features/scene/widgets/bottom_sheet_widget.dart | 6 +++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 0477738..4978b19 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -15,7 +15,8 @@ import 'package:syncrow_app/utils/context_extension.dart'; mixin SceneLogicHelper { bool isOnlyDelayOrDelayLast(List tasks) { final lastTask = tasks.last; - return tasks.every((task) => task.code == 'delay') || lastTask.code == 'delay'; + return tasks.every((task) => task.code == 'delay') || + lastTask.code == 'delay'; } void handleSaveButtonPress( @@ -44,12 +45,12 @@ mixin SceneLogicHelper { tasks.length, (index) { final task = tasks[index]; - if (task.code == 'delay') { + if (task.deviceId == 'delay') { return CreateSceneAction( entityId: tasks[index].deviceId, actionExecutor: 'delay', executorProperty: CreateSceneExecutorProperty( - functionCode: task.code, + functionCode: '', functionValue: task.operationalValues.first.value, delaySeconds: 0, ), @@ -121,7 +122,8 @@ mixin SceneLogicHelper { ); } else { return AlertDialogCountdown( - durationValue: listOfSceneStaticFunction[index].functionValue ?? taskItem.functionValue, + durationValue: listOfSceneStaticFunction[index].functionValue ?? + taskItem.functionValue, functionValue: taskItem.functionValue, function: listOfSceneStaticFunction[index], ); diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart index 30304b0..e83e9a1 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart @@ -60,8 +60,8 @@ class _AlertDialogCountdownState extends State { setState(() { durationInSeconds = newDuration.inSeconds; }); - context.read().add(SelectedValueEvent( - value: newDuration.inSeconds, code: widget.function.code)); + context.read().add( + SelectedValueEvent(value: newDuration.inSeconds, code: 'delay')); }, ), ); diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 887fa27..2b3ba88 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -111,11 +111,11 @@ class CustomBottomSheetWidget extends StatelessWidget { title: functions[0].operationName, onConfirm: () { final selectedValue = - context.read().selectedValues[functions[0].code]; + context.read().selectedValues['delay']; context.read().add(TempHoldSceneTasksEvent( deviceControlModel: DeviceControlModel( - deviceId: 'delay', - code: functions[0].code, + deviceId: '', + code: '', value: selectedValue, ), deviceId: 'delay', From ce94d91f8335e5d2c49f9e9fb2c24de46b634814 Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Mon, 1 Jul 2024 22:27:15 +0300 Subject: [PATCH 05/11] Fetched devices based on the unit id --- .../device_manager_bloc.dart | 20 +++------ .../scene/bloc/scene_bloc/scene_bloc.dart | 11 +++-- lib/features/scene/view/scene_view.dart | 7 ++- lib/services/api/api_links_endpoints.dart | 43 +++++++------------ lib/services/api/home_management_api.dart | 15 +++++++ 5 files changed, 47 insertions(+), 49 deletions(-) diff --git a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart index f648578..a8b1eb1 100644 --- a/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart +++ b/lib/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart @@ -25,11 +25,10 @@ class DeviceManagerBloc extends Bloc { static List? allCategories; - Future _onFetchAllDevices( - FetchAllDevices event, Emitter emit) async { + Future _onFetchAllDevices(FetchAllDevices event, Emitter emit) async { emit(state.copyWith(loading: true)); try { - final allDevices = await HomeManagementAPI.fetchDevicesByUserId(); + final allDevices = await HomeManagementAPI.fetchDevicesByUnitId(); emit(state.copyWith(devices: allDevices, loading: false)); } catch (e) { emit(state.copyWith(error: e.toString(), loading: false)); @@ -47,16 +46,14 @@ class DeviceManagerBloc extends Bloc { } } - void _onSelectCategory( - SelectCategory event, Emitter emit) { + void _onSelectCategory(SelectCategory event, Emitter emit) { for (var i = 0; i < allCategories!.length; i++) { allCategories![i].isSelected = i == event.index; } emit(state.copyWith(categoryChanged: true)); } - void _onUnselectAllCategories( - UnselectAllCategories event, Emitter emit) { + void _onUnselectAllCategories(UnselectAllCategories event, Emitter emit) { for (var category in allCategories!) { category.isSelected = false; } @@ -100,8 +97,7 @@ class DeviceManagerBloc extends Bloc { _updateDevicesStatus(category, emit); } - void _onTurnOnOffDevice( - TurnOnOffDevice event, Emitter emit) { + void _onTurnOnOffDevice(TurnOnOffDevice event, Emitter emit) { var device = event.device; device.isOnline = !device.isOnline!; DevicesCategoryModel category = allCategories!.firstWhere((category) { @@ -124,8 +120,7 @@ class DeviceManagerBloc extends Bloc { emit(state.copyWith(categoryChanged: true)); // Set category changed state } - void _updateDevicesStatus( - DevicesCategoryModel category, Emitter emit) { + void _updateDevicesStatus(DevicesCategoryModel category, Emitter emit) { if (category.devices != null && category.devices!.isNotEmpty) { bool? tempStatus = category.devices![0].isOnline; for (var device in category.devices!) { @@ -145,8 +140,7 @@ class DeviceManagerBloc extends Bloc { try { final deviceFunctions = await DevicesAPI.deviceFunctions(event.deviceId); - emit(state.copyWith( - functionsLoading: false, deviceFunctions: deviceFunctions)); + emit(state.copyWith(functionsLoading: false, deviceFunctions: deviceFunctions)); } catch (e) { emit(state.copyWith(functionsLoading: false, error: e.toString())); } diff --git a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart index 8613528..98b36cc 100644 --- a/lib/features/scene/bloc/scene_bloc/scene_bloc.dart +++ b/lib/features/scene/bloc/scene_bloc/scene_bloc.dart @@ -18,15 +18,18 @@ class SceneBloc extends Bloc { emit(SceneLoading()); try { - final scenes = await SceneApi.getScenesByUnitId(event.unitId); - emit(SceneLoaded(scenes)); + if (event.unitId.isNotEmpty) { + final scenes = await SceneApi.getScenesByUnitId(event.unitId); + emit(SceneLoaded(scenes)); + } else { + const SceneError(message: ''); + } } catch (e) { emit(const SceneError(message: 'Something went wrong')); } } - Future _onSceneTrigger( - SceneTrigger event, Emitter emit) async { + Future _onSceneTrigger(SceneTrigger event, Emitter emit) async { final currentState = state; if (currentState is SceneLoaded) { emit(SceneLoaded(currentState.scenes, loadingSceneId: event.sceneId)); diff --git a/lib/features/scene/view/scene_view.dart b/lib/features/scene/view/scene_view.dart index f6fb7fd..e89bae3 100644 --- a/lib/features/scene/view/scene_view.dart +++ b/lib/features/scene/view/scene_view.dart @@ -16,8 +16,8 @@ class SceneView extends StatelessWidget { @override Widget build(BuildContext context) { return BlocProvider( - create: (BuildContext context) => SceneBloc() - ..add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)), + create: (BuildContext context) => + SceneBloc()..add(LoadScenes(HomeCubit.getInstance().selectedSpace?.id ?? '')), child: BlocBuilder( builder: (context, state) { if (state is DeleteSceneSuccess) { @@ -36,8 +36,7 @@ class SceneView extends StatelessWidget { listener: (context, state) { if (state is SceneTriggerSuccess) { context.showCustomSnackbar( - message: - 'Scene ${state.sceneName} triggered successfully!'); + message: 'Scene ${state.sceneName} triggered successfully!'); } }, child: HomeCubit.getInstance().spaces?.isEmpty ?? true diff --git a/lib/services/api/api_links_endpoints.dart b/lib/services/api/api_links_endpoints.dart index b3becb7..d32bdba 100644 --- a/lib/services/api/api_links_endpoints.dart +++ b/lib/services/api/api_links_endpoints.dart @@ -9,8 +9,7 @@ abstract class ApiEndpoints { static const String deleteUser = '$baseUrl/authentication/user/delete/{id}'; static const String sendOtp = '$baseUrl/authentication/user/send-otp'; static const String verifyOtp = '$baseUrl/authentication/user/verify-otp'; - static const String forgetPassword = - '$baseUrl/authentication/user/forget-password'; + static const String forgetPassword = '$baseUrl/authentication/user/forget-password'; ////////////////////////////////////// Spaces /////////////////////////////////////// @@ -20,12 +19,10 @@ abstract class ApiEndpoints { static const String addCommunityToUser = '$baseUrl/community/user'; //GET static const String communityByUuid = '$baseUrl/community/{communityUuid}'; - static const String communityChild = - '$baseUrl/community/child/{communityUuid}'; + static const String communityChild = '$baseUrl/community/child/{communityUuid}'; static const String communityUser = '$baseUrl/community/user/{userUuid}'; //PUT - static const String renameCommunity = - '$baseUrl/community/rename/{communityUuid}'; + static const String renameCommunity = '$baseUrl/community/rename/{communityUuid}'; ///Building Module //POST @@ -34,12 +31,10 @@ abstract class ApiEndpoints { //GET static const String buildingByUuid = '$baseUrl/building/{buildingUuid}'; static const String buildingChild = '$baseUrl/building/child/{buildingUuid}'; - static const String buildingParent = - '$baseUrl/building/parent/{buildingUuid}'; + static const String buildingParent = '$baseUrl/building/parent/{buildingUuid}'; static const String buildingUser = '$baseUrl/building/user/{userUuid}'; //PUT - static const String renameBuilding = - '$baseUrl/building/rename/{buildingUuid}'; + static const String renameBuilding = '$baseUrl/building/rename/{buildingUuid}'; ///Floor Module //POST @@ -62,8 +57,7 @@ abstract class ApiEndpoints { static const String unitChild = '$baseUrl/unit/child/'; static const String unitParent = '$baseUrl/unit/parent/{unitUuid}'; static const String unitUser = '$baseUrl/unit/user/'; - static const String invitationCode = - '$baseUrl/unit/{unitUuid}/invitation-code'; + static const String invitationCode = '$baseUrl/unit/{unitUuid}/invitation-code'; static const String verifyInvitationCode = '$baseUrl/unit/user/verify-code'; //PUT @@ -86,8 +80,7 @@ abstract class ApiEndpoints { static const String controlGroup = '$baseUrl/group/control'; //GET static const String groupBySpace = '$baseUrl/group/{unitUuid}'; - static const String devicesByGroupName = - '$baseUrl/group/{unitUuid}/devices/{groupName}'; + static const String devicesByGroupName = '$baseUrl/group/{unitUuid}/devices/{groupName}'; static const String groupByUuid = '$baseUrl/group/{groupUuid}'; //DELETE @@ -99,19 +92,16 @@ abstract class ApiEndpoints { static const String addDeviceToRoom = '$baseUrl/device/room'; static const String addDeviceToGroup = '$baseUrl/device/group'; static const String controlDevice = '$baseUrl/device/{deviceUuid}/control'; - static const String firmwareDevice = - '$baseUrl/device/{deviceUuid}/firmware/{firmwareVersion}'; + static const String firmwareDevice = '$baseUrl/device/{deviceUuid}/firmware/{firmwareVersion}'; static const String getDevicesByUserId = '$baseUrl/device/user/{userId}'; + static const String getDevicesByUnitId = '$baseUrl/device/unit/{unitUuid}'; //GET static const String deviceByRoom = '$baseUrl/device/room'; static const String deviceByUuid = '$baseUrl/device/{deviceUuid}'; - static const String deviceFunctions = - '$baseUrl/device/{deviceUuid}/functions'; - static const String gatewayApi = - '$baseUrl/device/gateway/{gatewayUuid}/devices'; - static const String deviceFunctionsStatus = - '$baseUrl/device/{deviceUuid}/functions/status'; + static const String deviceFunctions = '$baseUrl/device/{deviceUuid}/functions'; + static const String gatewayApi = '$baseUrl/device/gateway/{gatewayUuid}/devices'; + static const String deviceFunctionsStatus = '$baseUrl/device/{deviceUuid}/functions/status'; ///Device Permission Module //POST @@ -119,16 +109,14 @@ abstract class ApiEndpoints { //GET static const String devicePermissionList = '$baseUrl/device-permission/list'; //PUT - static const String editDevicePermission = - '$baseUrl/device-permission/edit/{userId}'; + static const String editDevicePermission = '$baseUrl/device-permission/edit/{userId}'; static const String assignDeviceToRoom = '$baseUrl/device/room'; /// Scene API //////////////////// /// POST static const String createScene = '$baseUrl/scene/tap-to-run'; - static const String triggerScene = - '$baseUrl/scene/tap-to-run/trigger/{sceneId}'; + static const String triggerScene = '$baseUrl/scene/tap-to-run/trigger/{sceneId}'; /// GET static const String getUnitScenes = '$baseUrl/scene/tap-to-run/{unitUuid}'; @@ -139,8 +127,7 @@ abstract class ApiEndpoints { static const String updateScene = '$baseUrl/scene/tap-to-run/{sceneId}'; /// DELETE - static const String deleteScene = - '$baseUrl/scene/tap-to-run/{unitUuid}/{sceneId}'; + static const String deleteScene = '$baseUrl/scene/tap-to-run/{unitUuid}/{sceneId}'; //////////////////////Door Lock ////////////////////// //online diff --git a/lib/services/api/home_management_api.dart b/lib/services/api/home_management_api.dart index 78923ec..b49e8d7 100644 --- a/lib/services/api/home_management_api.dart +++ b/lib/services/api/home_management_api.dart @@ -1,4 +1,5 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/auth/model/user_model.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/services/api/api_links_endpoints.dart'; @@ -23,6 +24,20 @@ class HomeManagementAPI { return list; } + static Future> fetchDevicesByUnitId() async { + List list = []; + await _httpService.get( + path: ApiEndpoints.getDevicesByUnitId + .replaceAll("{unitUuid}", HomeCubit.getInstance().selectedSpace?.id ?? ''), + showServerMessage: false, + expectedResponseModel: (json) { + json.forEach((value) { + list.add(DeviceModel.fromJson(value)); + }); + }); + return list; + } + static Future> assignDeviceToRoom(Map body) async { try { final response = await _httpService.put( From 75fe80e72ab6b6350a6e4d5d359ee7b4736fd557 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Mon, 1 Jul 2024 22:31:50 +0300 Subject: [PATCH 06/11] commit last changes --- .../bloc/create_scene/create_scene_bloc.dart | 4 +- .../scene/helper/scene_logic_helper.dart | 4 +- .../helper/scene_operations_data_helper.dart | 80 ++++++++++--------- .../scene/model/create_scene_model.dart | 6 +- .../scene/model/scene_details_model.dart | 4 +- lib/features/scene/view/scene_tasks_view.dart | 13 +-- .../widgets/create_scene_save_button.dart | 2 +- 7 files changed, 60 insertions(+), 53 deletions(-) diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index 0c8fec8..39d929d 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -158,8 +158,8 @@ class CreateSceneBloc extends Bloc try { final response = await SceneApi.getSceneDetails(event.sceneId); if (response.id.isNotEmpty) { - tasksList = List.from(getTaskListFunctionsFromApi( - actions: response.actions, deviceId: response.id)); + tasksList = List.from( + getTaskListFunctionsFromApi(actions: response.actions)); emit(AddSceneTask( tasksList: tasksList, )); diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index 4978b19..cda1e50 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -51,8 +51,8 @@ mixin SceneLogicHelper { actionExecutor: 'delay', executorProperty: CreateSceneExecutorProperty( functionCode: '', - functionValue: task.operationalValues.first.value, - delaySeconds: 0, + functionValue: '', + delaySeconds: task.operationalValues.first.value, ), ); } diff --git a/lib/features/scene/helper/scene_operations_data_helper.dart b/lib/features/scene/helper/scene_operations_data_helper.dart index c1e2079..701419a 100644 --- a/lib/features/scene/helper/scene_operations_data_helper.dart +++ b/lib/features/scene/helper/scene_operations_data_helper.dart @@ -458,11 +458,6 @@ mixin SceneOperationsDataHelper { icon: Assets.assetsAcPower, description: "ON", value: true), SceneOperationalValue( icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, - description: "Reverse Switch", - value: null, - ), ], ), SceneStaticFunction( @@ -477,11 +472,6 @@ mixin SceneOperationsDataHelper { icon: Assets.assetsAcPower, description: "ON", value: true), SceneOperationalValue( icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, - description: "Reverse Switch", - value: null, - ), ], ), SceneStaticFunction( @@ -496,11 +486,6 @@ mixin SceneOperationsDataHelper { icon: Assets.assetsAcPower, description: "ON", value: true), SceneOperationalValue( icon: Assets.assetsAcPowerOFF, description: "OFF", value: false), - SceneOperationalValue( - icon: Assets.assetsSceneRefresh, - description: "Reverse Switch", - value: null, - ), ], ), SceneStaticFunction( @@ -665,18 +650,37 @@ mixin SceneOperationsDataHelper { /// List getTaskListFunctionsFromApi({ required List actions, - required String deviceId, }) { List functions = []; for (var action in actions) { + if (action.entityId == 'delay') { + functions.add( + SceneStaticFunction( + deviceId: action.entityId, + deviceName: 'delay', + deviceIcon: Assets.delay, + icon: Assets.delay, + operationName: 'delay', + functionValue: action.executorProperty.delaySeconds, + code: '', + operationalValues: [ + SceneOperationalValue( + icon: '', + description: "", + value: action.executorProperty.delaySeconds, + ), + ], + ), + ); + } ExecutorProperty executorProperty = action.executorProperty; switch (executorProperty.functionCode) { case 'sensitivity': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Presence Sensor', deviceIcon: Assets.assetsIconsSensors, icon: Assets.assetsSensitivityFunction, @@ -741,7 +745,7 @@ mixin SceneOperationsDataHelper { case 'normal_open_switch': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'WIFI LOCK PRO', deviceIcon: Assets.assetsIconsDoorLock, icon: Assets.assetsIconsDoorLock, @@ -763,7 +767,7 @@ mixin SceneOperationsDataHelper { case 'far_detection': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Human Presence Sensor', deviceIcon: Assets.assetsIconsSensors, icon: Assets.assetsFarDetection, @@ -826,7 +830,7 @@ mixin SceneOperationsDataHelper { case 'motion_sensitivity_value': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Human Presence Sensor', deviceIcon: Assets.assetsIconsSensors, icon: Assets.assetsMotionDetection, @@ -866,7 +870,7 @@ mixin SceneOperationsDataHelper { case 'motionless_sensitivity': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Human Presence Sensor', deviceIcon: Assets.assetsIconsSensors, icon: Assets.assetsMotionlessDetection, @@ -911,7 +915,7 @@ mixin SceneOperationsDataHelper { case 'indicator': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Human Presence Sensor', deviceIcon: Assets.assetsIconsSensors, icon: Assets.assetsIndicator, @@ -933,7 +937,7 @@ mixin SceneOperationsDataHelper { case 'presence_time': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Human Presence Sensor', deviceIcon: Assets.assetsIconsSensors, icon: Assets.assetsNobodyTime, @@ -949,7 +953,7 @@ mixin SceneOperationsDataHelper { case 'switch_alarm_sound': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Multi-Mode Gateway Z-W-B', deviceIcon: Assets.assetsIconsGateway, icon: Assets.assetsSwitchAlarmSound, @@ -973,7 +977,7 @@ mixin SceneOperationsDataHelper { case 'master_state': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Multi-Mode Gateway Z-W-B', deviceIcon: Assets.assetsIconsGateway, icon: Assets.assetsMasterState, @@ -998,7 +1002,7 @@ mixin SceneOperationsDataHelper { case 'factory_reset': functions.add( SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Multi-Mode Gateway Z-W-B', deviceIcon: Assets.assetsIconsGateway, icon: Assets.assetsFactoryReset, @@ -1021,7 +1025,7 @@ mixin SceneOperationsDataHelper { break; case 'switch_1': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: '3 Gang Button Switch L-L', deviceIcon: Assets.assetsIcons3GangSwitch, icon: Assets.assetsAcPower, @@ -1048,7 +1052,7 @@ mixin SceneOperationsDataHelper { break; case 'switch_2': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: '3 Gang Button Switch L-L', deviceIcon: Assets.assetsIcons3GangSwitch, icon: Assets.assetsAcPower, @@ -1072,7 +1076,7 @@ mixin SceneOperationsDataHelper { break; case 'switch_3': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: '3 Gang Button Switch L-L', deviceIcon: Assets.assetsIcons3GangSwitch, icon: Assets.assetsAcPower, @@ -1096,7 +1100,7 @@ mixin SceneOperationsDataHelper { break; case 'countdown_1': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: '3 Gang Button Switch L-L', deviceIcon: Assets.assetsIcons3GangSwitch, icon: Assets.assetsLightCountdown, @@ -1110,7 +1114,7 @@ mixin SceneOperationsDataHelper { break; case 'countdown_2': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: '3 Gang Button Switch L-L', deviceIcon: Assets.assetsIcons3GangSwitch, icon: Assets.assetsLightCountdown, @@ -1124,7 +1128,7 @@ mixin SceneOperationsDataHelper { break; case 'countdown_3': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: '3 Gang Button Switch L-L', deviceIcon: Assets.assetsIcons3GangSwitch, icon: Assets.assetsLightCountdown, @@ -1138,7 +1142,7 @@ mixin SceneOperationsDataHelper { break; case 'switch': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Smart AC Thermostat - Grey - Model A', deviceIcon: Assets.assetsIconsAC, icon: Assets.assetsAcPower, @@ -1161,14 +1165,14 @@ mixin SceneOperationsDataHelper { break; case 'temp_set': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Smart AC Thermostat - Grey - Model A', deviceIcon: Assets.assetsIconsAC, icon: Assets.assetsTempreture, operationName: 'Set Temperature', code: 'temp_set', functionValue: executorProperty.functionValue != null - ? ((executorProperty.functionValue / 10) as double).toInt() + ? ((executorProperty.functionValue! / 10) as double).toInt() : null, operationalValues: [ SceneOperationalValue( @@ -1181,7 +1185,7 @@ mixin SceneOperationsDataHelper { break; case 'mode': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Smart AC Thermostat - Grey - Model A', deviceIcon: Assets.assetsIconsAC, icon: Assets.assetsFreezing, @@ -1209,7 +1213,7 @@ mixin SceneOperationsDataHelper { break; case 'level': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Smart AC Thermostat - Grey - Model A', deviceIcon: Assets.assetsIconsAC, icon: Assets.assetsFanSpeed, @@ -1242,7 +1246,7 @@ mixin SceneOperationsDataHelper { break; case 'child_lock': functions.add(SceneStaticFunction( - deviceId: deviceId, + deviceId: action.entityId, deviceName: 'Smart AC Thermostat - Grey - Model A', deviceIcon: Assets.assetsIconsAC, icon: Assets.assetsChildLock, diff --git a/lib/features/scene/model/create_scene_model.dart b/lib/features/scene/model/create_scene_model.dart index 41a0d53..53dc344 100644 --- a/lib/features/scene/model/create_scene_model.dart +++ b/lib/features/scene/model/create_scene_model.dart @@ -183,9 +183,9 @@ class CreateSceneExecutorProperty { Map toMap() { return { - 'functionCode': functionCode, - 'functionValue': functionValue, - 'delaySeconds': delaySeconds, + if (functionCode.isNotEmpty == true) 'functionCode': functionCode, + if (functionValue != '') 'functionValue': functionValue, + if (delaySeconds > 0) 'delaySeconds': delaySeconds, }; } diff --git a/lib/features/scene/model/scene_details_model.dart b/lib/features/scene/model/scene_details_model.dart index 069b18e..5ed5d1c 100644 --- a/lib/features/scene/model/scene_details_model.dart +++ b/lib/features/scene/model/scene_details_model.dart @@ -81,8 +81,8 @@ class ExecutorProperty { factory ExecutorProperty.fromJson(Map json) => ExecutorProperty( functionCode: json["functionCode"] ?? '', - functionValue: json["functionValue"], - delaySeconds: json["delaySeconds"], + functionValue: json["functionValue"] ?? '', + delaySeconds: json["delaySeconds"] ?? 0, ); Map toJson() => { diff --git a/lib/features/scene/view/scene_tasks_view.dart b/lib/features/scene/view/scene_tasks_view.dart index 5183faf..134916c 100644 --- a/lib/features/scene/view/scene_tasks_view.dart +++ b/lib/features/scene/view/scene_tasks_view.dart @@ -33,11 +33,14 @@ class SceneTasksView extends StatelessWidget { SizedBox( width: 40, child: GestureDetector( - onTap: () { - context.customBottomSheet( - child: DeleteBottomSheetContent(sceneId: sceneSettings.sceneId), - ); - }, + onTap: sceneSettings.sceneName.isEmpty + ? null + : () { + context.customBottomSheet( + child: DeleteBottomSheetContent( + sceneId: sceneSettings.sceneId), + ); + }, child: SvgPicture.asset( Assets.assetsIconsSettings, colorFilter: const ColorFilter.mode( diff --git a/lib/features/scene/widgets/create_scene_save_button.dart b/lib/features/scene/widgets/create_scene_save_button.dart index 179153d..5a31914 100644 --- a/lib/features/scene/widgets/create_scene_save_button.dart +++ b/lib/features/scene/widgets/create_scene_save_button.dart @@ -122,7 +122,7 @@ class _CreateSceneSaveButtonState extends State ), isLoading: state is CreateSceneLoading, child: BodyLarge( - text: 'Save', + text: widget.sceneName.isNotEmpty ? 'Update' : 'Save', style: context.bodyLarge.copyWith(color: Colors.white), ), ); From e9300518b1fe7667ab9da6133ce79a3ce256efd6 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Mon, 1 Jul 2024 22:45:40 +0300 Subject: [PATCH 07/11] push --- .../widgets/alert_dialogs/alert_dialog_countdown.dart | 7 +++++-- lib/features/scene/widgets/bottom_sheet_widget.dart | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart index e83e9a1..73371a0 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_countdown.dart @@ -60,8 +60,11 @@ class _AlertDialogCountdownState extends State { setState(() { durationInSeconds = newDuration.inSeconds; }); - context.read().add( - SelectedValueEvent(value: newDuration.inSeconds, code: 'delay')); + context.read().add(SelectedValueEvent( + value: newDuration.inSeconds, + code: widget.function.deviceId == 'delay' + ? 'delay' + : widget.function.code)); }, ), ); diff --git a/lib/features/scene/widgets/bottom_sheet_widget.dart b/lib/features/scene/widgets/bottom_sheet_widget.dart index 2b3ba88..9ef5408 100644 --- a/lib/features/scene/widgets/bottom_sheet_widget.dart +++ b/lib/features/scene/widgets/bottom_sheet_widget.dart @@ -126,6 +126,7 @@ class CustomBottomSheetWidget extends StatelessWidget { )); context.read().add(AddTaskEvent()); Navigator.pop(context); + Navigator.pop(context); }, onDismiss: () { final tempTaskList = context.read().tempTasksList; From a4b3229d65d99921f11f268c596f303cd5003dba Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Tue, 2 Jul 2024 00:07:32 +0300 Subject: [PATCH 08/11] push dialog confirm selection safety --- lib/features/scene/view/device_functions_view.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/features/scene/view/device_functions_view.dart b/lib/features/scene/view/device_functions_view.dart index 5ad9974..070b8a2 100644 --- a/lib/features/scene/view/device_functions_view.dart +++ b/lib/features/scene/view/device_functions_view.dart @@ -46,9 +46,7 @@ class DeviceFunctionsView extends StatelessWidget actions: [ TextButton( onPressed: () { - context - .read() - .add( AddTaskEvent()); + context.read().add(AddTaskEvent()); Navigator.popUntil(context, (route) { return route.settings.name == Routes.sceneTasksRoute; }); @@ -135,6 +133,7 @@ class DeviceFunctionsView extends StatelessWidget final functionValues = context .read() .selectedValues[functions[index].code]; + context.customAlertDialog( alertBody: functions[index].code == 'temp_set' ? AlertDialogTemperatureBody( @@ -166,6 +165,9 @@ class DeviceFunctionsView extends StatelessWidget final selectedValue = context .read() .selectedValues[functions[index].code]; + if (selectedValue == null) { + return; + } context .read() .add(TempHoldSceneTasksEvent( From b392f9050707ce0859c87b03deb19ab41450443a Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Tue, 2 Jul 2024 12:39:09 +0300 Subject: [PATCH 09/11] fix bugs --- lib/features/scene/helper/scene_logic_helper.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/features/scene/helper/scene_logic_helper.dart b/lib/features/scene/helper/scene_logic_helper.dart index cda1e50..9339d71 100644 --- a/lib/features/scene/helper/scene_logic_helper.dart +++ b/lib/features/scene/helper/scene_logic_helper.dart @@ -52,7 +52,7 @@ mixin SceneLogicHelper { executorProperty: CreateSceneExecutorProperty( functionCode: '', functionValue: '', - delaySeconds: task.operationalValues.first.value, + delaySeconds: task.functionValue, ), ); } @@ -61,7 +61,7 @@ mixin SceneLogicHelper { actionExecutor: 'device_issue', executorProperty: CreateSceneExecutorProperty( functionCode: task.code, - functionValue: task.operationalValues.first.value, + functionValue: task.functionValue, delaySeconds: 0, ), ); From 97e0f29ac68f10af4dca7217b7f5c964f4051a20 Mon Sep 17 00:00:00 2001 From: ashrafzarkanisala Date: Tue, 2 Jul 2024 13:10:30 +0300 Subject: [PATCH 10/11] remove coments --- .../widgets/alert_dialogs/alert_dialog_functions_body.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart b/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart index 9c71ef5..e0ff6a4 100644 --- a/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart +++ b/lib/features/scene/widgets/alert_dialogs/alert_dialog_functions_body.dart @@ -29,9 +29,9 @@ class _AlertDialogFunctionsOperationsBodyState didChangeDependencies() { super.didChangeDependencies(); final tempTaskList = context.read().tempTasksList; - // if (tempTaskList.isEmpty) { - // context.read().add(const ClearTempTaskListEvent()); - // } else + + + if (tempTaskList.isNotEmpty) { for (var element in tempTaskList) { if (element.code == widget.functions[widget.index].code) { From c7d26d0e6e8131ddfba492fb636784c1b0276aca Mon Sep 17 00:00:00 2001 From: Abdullah Alassaf Date: Tue, 2 Jul 2024 13:14:17 +0300 Subject: [PATCH 11/11] Bug fixes, and updated the build number --- android/app/src/main/AndroidManifest.xml | 4 +- lib/features/auth/bloc/auth_cubit.dart | 58 ++++++++++--------- .../bloc/create_scene/create_scene_bloc.dart | 25 +++----- lib/features/scene/view/scene_view.dart | 23 ++++++-- pubspec.yaml | 2 +- 5 files changed, 61 insertions(+), 51 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index fdf5596..9287665 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -5,7 +5,9 @@ + android:icon="@mipmap/ic_launcher" + android:allowBackup="false" + > { } getTokenAndValidate() async { - emit(AuthTokenLoading()); - const storage = FlutterSecureStorage(); - final firstLaunch = - await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true; + try { + emit(AuthTokenLoading()); + const storage = FlutterSecureStorage(); + final firstLaunch = + await SharedPreferencesHelper.readBoolFromSP(StringsManager.firstLaunch) ?? true; - if (firstLaunch) { - storage.deleteAll(); - } - - await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false); - - final value = await storage.read(key: Token.loginAccessTokenKey) ?? ''; - if (value.isEmpty) { - emit(AuthTokenError(message: "Token not found")); - return; - } - - final tokenData = Token.decodeToken(value); - - if (tokenData.containsKey('exp')) { - final exp = tokenData['exp'] ?? 0; - final currentTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; - - if (currentTime < exp) { - emit(AuthTokenSuccess()); - } else { - emit(AuthTokenError(message: "Token expired")); + if (firstLaunch) { + storage.deleteAll(); } - } else { + + await SharedPreferencesHelper.saveBoolToSP(StringsManager.firstLaunch, false); + + final value = await storage.read(key: Token.loginAccessTokenKey) ?? ''; + if (value.isEmpty) { + emit(AuthTokenError(message: "Token not found")); + return; + } + + final tokenData = Token.decodeToken(value); + + if (tokenData.containsKey('exp')) { + final exp = tokenData['exp'] ?? 0; + final currentTime = DateTime.now().millisecondsSinceEpoch ~/ 1000; + + if (currentTime < exp) { + emit(AuthTokenSuccess()); + } else { + emit(AuthTokenError(message: "Token expired")); + } + } else { + emit(AuthTokenError(message: "Something went wrong")); + } + } catch (_) { emit(AuthTokenError(message: "Something went wrong")); } } diff --git a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart index 39d929d..ad6ab58 100644 --- a/lib/features/scene/bloc/create_scene/create_scene_bloc.dart +++ b/lib/features/scene/bloc/create_scene/create_scene_bloc.dart @@ -30,8 +30,7 @@ class CreateSceneBloc extends Bloc List tempTasksList = []; final Map selectedValues = {}; - FutureOr _onAddSceneTask( - AddTaskEvent event, Emitter emit) { + FutureOr _onAddSceneTask(AddTaskEvent event, Emitter emit) { final copyList = List.from(tempTasksList); tasksList.addAll(copyList); tempTasksList.clear(); @@ -90,15 +89,13 @@ class CreateSceneBloc extends Bloc emit(AddSceneTask(tasksList: tasksList)); } - FutureOr _selectedValue( - SelectedValueEvent event, Emitter emit) { + FutureOr _selectedValue(SelectedValueEvent event, Emitter emit) { selectedValues[event.code] = event.value; emit(SelectedTaskValueState(value: event.value)); emit(AddSceneTask(tasksList: tasksList)); } - FutureOr _removeTaskById( - RemoveTaskByIdEvent event, Emitter emit) { + FutureOr _removeTaskById(RemoveTaskByIdEvent event, Emitter emit) { emit(CreateSceneLoading()); for (var element in tasksList) { @@ -145,8 +142,7 @@ class CreateSceneBloc extends Bloc } } - FutureOr _clearTaskList( - ClearTaskListEvent event, Emitter emit) { + FutureOr _clearTaskList(ClearTaskListEvent event, Emitter emit) { tasksList.clear(); emit(AddSceneTask(tasksList: tasksList)); } @@ -158,8 +154,8 @@ class CreateSceneBloc extends Bloc try { final response = await SceneApi.getSceneDetails(event.sceneId); if (response.id.isNotEmpty) { - tasksList = List.from( - getTaskListFunctionsFromApi(actions: response.actions)); + tasksList = + List.from(getTaskListFunctionsFromApi(actions: response.actions)); emit(AddSceneTask( tasksList: tasksList, )); @@ -171,8 +167,7 @@ class CreateSceneBloc extends Bloc } } - FutureOr _clearTempTaskList( - ClearTempTaskListEvent event, Emitter emit) { + FutureOr _clearTempTaskList(ClearTempTaskListEvent event, Emitter emit) { tempTasksList.clear(); selectedValues.clear(); emit(TempHoldSceneTask(tempTasksList: tempTasksList)); @@ -188,13 +183,11 @@ class CreateSceneBloc extends Bloc } } - FutureOr _deleteScene( - DeleteSceneEvent event, Emitter emit) async { + FutureOr _deleteScene(DeleteSceneEvent event, Emitter emit) async { emit(DeleteSceneLoading()); try { - final response = await SceneApi.deleteScene( - sceneId: event.sceneId, unitUuid: event.unitUuid); + final response = await SceneApi.deleteScene(sceneId: event.sceneId, unitUuid: event.unitUuid); if (response == true) { emit(const DeleteSceneSuccess(true)); } else { diff --git a/lib/features/scene/view/scene_view.dart b/lib/features/scene/view/scene_view.dart index e89bae3..83a537a 100644 --- a/lib/features/scene/view/scene_view.dart +++ b/lib/features/scene/view/scene_view.dart @@ -7,6 +7,7 @@ import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart'; import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_grid_view.dart'; import 'package:syncrow_app/features/scene/widgets/scene_view_widget/scene_header.dart'; import 'package:syncrow_app/features/shared_widgets/create_unit.dart'; +import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart'; import 'package:syncrow_app/utils/context_extension.dart'; @@ -60,12 +61,22 @@ class SceneView extends StatelessWidget { ); } if (state is SceneLoaded) { - return Expanded( - child: SceneGrid( - scenes: state.scenes, - loadingSceneId: state.loadingSceneId, - ), - ); + if (state.scenes.isNotEmpty) { + return Expanded( + child: SceneGrid( + scenes: state.scenes, + loadingSceneId: state.loadingSceneId, + ), + ); + } else { + return const Expanded( + child: Center( + child: BodyMedium( + text: 'No scenes have been added yet', + ), + ), + ); + } } return const SizedBox(); diff --git a/pubspec.yaml b/pubspec.yaml index 9f65699..59f680d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 1.0.8+9 +version: 1.0.0+10 environment: sdk: ">=3.0.6 <4.0.0"