mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 22:44:54 +00:00
26 lines
996 B
Dart
26 lines
996 B
Dart
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';
|
|
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);
|
|
}
|
|
|
|
FutureOr<void> _handleTabChanged(
|
|
TabChanged event, Emitter<TabBarState> emit) {
|
|
if (event.roomId == "-1") {
|
|
deviceManagerBloc.add(FetchAllDevices());
|
|
} else {
|
|
deviceManagerBloc.add(FetchDevicesByRoomId(event.roomId));
|
|
}
|
|
emit(TabSelected(
|
|
roomId: event.roomId, selectedTabIndex: event.selectedIndex));
|
|
}
|
|
}
|