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; + } }