mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
refactor: rename tab change events and states for consistency, and to match bloc
s naming convention.
This commit is contained in:
@ -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<TabBarEvent, TabBarState> {
|
||||
final DeviceManagerBloc deviceManagerBloc;
|
||||
TabBarBloc(this.deviceManagerBloc) : super(const Initial()) {
|
||||
on<TabChanged>(_handleTabChanged);
|
||||
TabBarBloc(this.deviceManagerBloc) : super(const TabBarInitialState()) {
|
||||
on<TabBarTabChangedEvent>(_onTabBarTabChangedEvent);
|
||||
}
|
||||
|
||||
FutureOr<void> _handleTabChanged(
|
||||
TabChanged event, Emitter<TabBarState> emit) {
|
||||
final DeviceManagerBloc deviceManagerBloc;
|
||||
|
||||
void _onTabBarTabChangedEvent(
|
||||
TabBarTabChangedEvent event,
|
||||
Emitter<TabBarState> 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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});
|
||||
}
|
||||
|
@ -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});
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ class _SceneRoomsTabBarDevicesViewState extends State<SceneRoomsTabBarDevicesVie
|
||||
final index = _tabController.index;
|
||||
|
||||
context.read<TabBarBloc>().add(
|
||||
TabChanged(
|
||||
TabBarTabChangedEvent(
|
||||
selectedIndex: index,
|
||||
roomId: rooms[index].id ?? '',
|
||||
unit: selectedSpace,
|
||||
|
@ -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(
|
||||
|
@ -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<DeviceManagerBloc>())
|
||||
..add(TabChanged(
|
||||
..add(TabBarTabChangedEvent(
|
||||
selectedIndex: 0,
|
||||
roomId: '-1',
|
||||
unit: SpaceModel(
|
||||
|
Reference in New Issue
Block a user