From f2412aa8670f9ce7d99c60e3af5bc16a06fb9140 Mon Sep 17 00:00:00 2001 From: Faris Armoush Date: Wed, 16 Apr 2025 16:08:57 +0300 Subject: [PATCH] refactor: extract device fetching logic into a separate method for improved readability --- .../scene/bloc/tab_change/tab_change_bloc.dart | 14 +++++++++----- .../widgets/scene_devices/scene_devices_body.dart | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/features/scene/bloc/tab_change/tab_change_bloc.dart b/lib/features/scene/bloc/tab_change/tab_change_bloc.dart index de72560..62f84bb 100644 --- a/lib/features/scene/bloc/tab_change/tab_change_bloc.dart +++ b/lib/features/scene/bloc/tab_change/tab_change_bloc.dart @@ -15,11 +15,7 @@ class TabBarBloc extends Bloc { TabBarTabChangedEvent event, Emitter emit, ) { - if (event.roomId == "-1") { - deviceManagerBloc.add(FetchAllDevices()); - } else { - deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId, event.unit)); - } + _getDevices(event); emit( TabBarTabSelectedState( @@ -28,4 +24,12 @@ class TabBarBloc extends Bloc { ), ); } + + void _getDevices(TabBarTabChangedEvent event) { + if (event.roomId == "-1") { + deviceManagerBloc.add(FetchAllDevices()); + } else { + deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId, event.unit)); + } + } } diff --git a/lib/features/scene/widgets/scene_devices/scene_devices_body.dart b/lib/features/scene/widgets/scene_devices/scene_devices_body.dart index 50b3486..25fe8e6 100644 --- a/lib/features/scene/widgets/scene_devices/scene_devices_body.dart +++ b/lib/features/scene/widgets/scene_devices/scene_devices_body.dart @@ -58,6 +58,7 @@ class SceneDevicesBody extends StatelessWidget { ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?; final deviceStatusChangesScene = CreateSceneEnum.deviceStatusChanges.name; final sceneType = routeArguments?.sceneType; + return sceneType == deviceStatusChangesScene; }