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 7fc18db..de72560 100644 --- a/lib/features/scene/bloc/tab_change/tab_change_bloc.dart +++ b/lib/features/scene/bloc/tab_change/tab_change_bloc.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_event.dart'; @@ -7,19 +5,27 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_state.dart'; class TabBarBloc extends Bloc { - final DeviceManagerBloc deviceManagerBloc; - TabBarBloc(this.deviceManagerBloc) : super(const Initial()) { - on(_handleTabChanged); + TabBarBloc(this.deviceManagerBloc) : super(const TabBarInitialState()) { + on(_onTabBarTabChangedEvent); } - FutureOr _handleTabChanged( - TabChanged event, Emitter emit) { + final DeviceManagerBloc deviceManagerBloc; + + void _onTabBarTabChangedEvent( + TabBarTabChangedEvent event, + Emitter emit, + ) { if (event.roomId == "-1") { deviceManagerBloc.add(FetchAllDevices()); } else { - deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId,event.unit)); + deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId, event.unit)); } - emit(TabSelected( - roomId: event.roomId, selectedTabIndex: event.selectedIndex)); + + emit( + TabBarTabSelectedState( + roomId: event.roomId, + selectedTabIndex: event.selectedIndex, + ), + ); } } diff --git a/lib/features/scene/bloc/tab_change/tab_change_event.dart b/lib/features/scene/bloc/tab_change/tab_change_event.dart index f39d823..aeeda5e 100644 --- a/lib/features/scene/bloc/tab_change/tab_change_event.dart +++ b/lib/features/scene/bloc/tab_change/tab_change_event.dart @@ -4,10 +4,14 @@ abstract class TabBarEvent { const TabBarEvent(); } -class TabChanged extends TabBarEvent { +class TabBarTabChangedEvent extends TabBarEvent { + const TabBarTabChangedEvent({ + required this.selectedIndex, + required this.roomId, + required this.unit, + }); + final int selectedIndex; final String roomId; final SpaceModel unit; - const TabChanged( - {required this.selectedIndex, required this.roomId, required this.unit}); } diff --git a/lib/features/scene/bloc/tab_change/tab_change_state.dart b/lib/features/scene/bloc/tab_change/tab_change_state.dart index 4a42c44..4970f21 100644 --- a/lib/features/scene/bloc/tab_change/tab_change_state.dart +++ b/lib/features/scene/bloc/tab_change/tab_change_state.dart @@ -2,12 +2,16 @@ abstract class TabBarState { const TabBarState(); } -class Initial extends TabBarState { - const Initial(); +class TabBarInitialState extends TabBarState { + const TabBarInitialState(); } -class TabSelected extends TabBarState { +class TabBarTabSelectedState extends TabBarState { + const TabBarTabSelectedState({ + required this.roomId, + required this.selectedTabIndex, + }); + final int selectedTabIndex; final String roomId; - const TabSelected({required this.roomId, required this.selectedTabIndex}); } diff --git a/lib/features/scene/view/scene_rooms_tabbar.dart b/lib/features/scene/view/scene_rooms_tabbar.dart index ccc2bc2..d47f43f 100644 --- a/lib/features/scene/view/scene_rooms_tabbar.dart +++ b/lib/features/scene/view/scene_rooms_tabbar.dart @@ -64,7 +64,7 @@ class _SceneRoomsTabBarDevicesViewState extends State().add( - TabChanged( + TabBarTabChangedEvent( selectedIndex: index, roomId: rooms[index].id ?? '', unit: selectedSpace, 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 1a89142..50b3486 100644 --- a/lib/features/scene/widgets/scene_devices/scene_devices_body.dart +++ b/lib/features/scene/widgets/scene_devices/scene_devices_body.dart @@ -31,7 +31,7 @@ class SceneDevicesBody extends StatelessWidget { SceneDevicesBodyTabBar( tabController: tabController, rooms: rooms, - selectedRoomId: state is TabSelected ? state.roomId : '-1', + selectedRoomId: state is TabBarTabSelectedState ? state.roomId : '-1', ), Expanded( child: TabBarView( diff --git a/lib/navigation/router.dart b/lib/navigation/router.dart index c09a307..2ab5b39 100644 --- a/lib/navigation/router.dart +++ b/lib/navigation/router.dart @@ -3,8 +3,8 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:syncrow_app/features/app_layout/model/community_model.dart'; import 'package:syncrow_app/features/app_layout/model/space_model.dart'; import 'package:syncrow_app/features/app_layout/view/app_layout.dart'; -import 'package:syncrow_app/features/auth/view/otp_view.dart'; import 'package:syncrow_app/features/auth/view/login_view.dart'; +import 'package:syncrow_app/features/auth/view/otp_view.dart'; import 'package:syncrow_app/features/auth/view/sign_up_view.dart'; import 'package:syncrow_app/features/dashboard/view/dashboard_view.dart'; import 'package:syncrow_app/features/devices/bloc/device_manager_bloc/device_manager_bloc.dart'; @@ -17,11 +17,12 @@ import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_bloc.dart' import 'package:syncrow_app/features/scene/bloc/tab_change/tab_change_event.dart'; import 'package:syncrow_app/features/scene/view/device_functions_view.dart'; import 'package:syncrow_app/features/scene/view/scene_auto_settings.dart'; -import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart'; import 'package:syncrow_app/features/scene/view/scene_rooms_tabbar.dart'; +import 'package:syncrow_app/features/scene/view/scene_tasks_view.dart'; import 'package:syncrow_app/features/scene/view/scene_view.dart'; import 'package:syncrow_app/features/scene/view/smart_automation_select_route.dart'; import 'package:syncrow_app/features/splash/view/splash_view.dart'; + import 'routing_constants.dart'; class Router { @@ -88,7 +89,7 @@ class Router { BlocProvider( create: (BuildContext context) => TabBarBloc(context.read()) - ..add(TabChanged( + ..add(TabBarTabChangedEvent( selectedIndex: 0, roomId: '-1', unit: SpaceModel(