From 09f21239460c7a23d7c4a6b1e87a2f43db58e7fc Mon Sep 17 00:00:00 2001 From: raf-dev1 Date: Tue, 17 Jun 2025 16:21:01 +0300 Subject: [PATCH 1/2] bug fixed it is locally change the state now --- .../bloc/routine_bloc/routine_bloc.dart | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart index ca8aac06..f13e24d4 100644 --- a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart @@ -1422,15 +1422,17 @@ class RoutineBloc extends Bloc { event.automationId, event.automationStatusUpdate, projectId); if (success) { - final updatedAutomations = await SceneApi.getAutomationByUnitId( - event.automationStatusUpdate.spaceUuid, - event.communityId, - projectId); + // await SceneApi.getAutomationByUnitId( + // event.automationStatusUpdate.spaceUuid, + // event.communityId, + // projectId); // Remove from loading set safely + final updatedLoadingIds = {...state.loadingAutomationIds!} ..remove(event.automationId); - + final updatedAutomations = changeItemStateOnToggelingSceen( + state.automations, event.automationId); emit(state.copyWith( automations: updatedAutomations, loadingAutomationIds: updatedLoadingIds, @@ -1452,4 +1454,30 @@ class RoutineBloc extends Bloc { )); } } + + List changeItemStateOnToggelingSceen( + List oldSceen, String automationId) { + final updatedAutomations = oldSceen; + final temp = + updatedAutomations.firstWhere((element) => element.id == automationId); + final tempIndex = updatedAutomations.indexWhere( + (element) => element.id == automationId, + ); + updatedAutomations.removeWhere( + (element) => element.id == automationId, + ); + updatedAutomations.insert( + tempIndex, + ScenesModel( + id: temp.id, + name: temp.name, + status: temp.status == 'enable' ? 'disable' : 'enable', + type: temp.type, + spaceName: temp.spaceName, + spaceId: temp.spaceId, + communityId: temp.communityId, + ), + ); + return updatedAutomations; + } } From 1ba1aba54e56a92d839e6dc80653aff4b0d32e3b Mon Sep 17 00:00:00 2001 From: raf-dev1 Date: Wed, 18 Jun 2025 08:42:18 +0300 Subject: [PATCH 2/2] PR fixes and tested --- .../bloc/routine_bloc/routine_bloc.dart | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart index f13e24d4..af015158 100644 --- a/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart +++ b/lib/pages/routines/bloc/routine_bloc/routine_bloc.dart @@ -1457,27 +1457,21 @@ class RoutineBloc extends Bloc { List changeItemStateOnToggelingSceen( List oldSceen, String automationId) { - final updatedAutomations = oldSceen; - final temp = - updatedAutomations.firstWhere((element) => element.id == automationId); - final tempIndex = updatedAutomations.indexWhere( - (element) => element.id == automationId, - ); - updatedAutomations.removeWhere( - (element) => element.id == automationId, - ); - updatedAutomations.insert( - tempIndex, - ScenesModel( - id: temp.id, - name: temp.name, - status: temp.status == 'enable' ? 'disable' : 'enable', - type: temp.type, - spaceName: temp.spaceName, - spaceId: temp.spaceId, - communityId: temp.communityId, - ), - ); - return updatedAutomations; + return oldSceen.map((scene) { + if (scene.id == automationId) { + return ScenesModel( + id: scene.id, + sceneTuyaId: scene.sceneTuyaId, + name: scene.name, + status: scene.status == 'enable' ? 'disable' : 'enable', + type: scene.type, + spaceName: scene.spaceName, + spaceId: scene.spaceId, + communityId: scene.communityId, + icon: scene.icon, + ); + } + return scene; + }).toList(); } }