mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
87 lines
2.5 KiB
Dart
87 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
|
|
import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart';
|
|
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
|
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/widgets/scene_devices/scene_devices_body.dart';
|
|
|
|
import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart';
|
|
|
|
import 'package:syncrow_app/utils/resource_manager/constants.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/strings_manager.dart';
|
|
|
|
class SceneControlDevicesView extends StatefulWidget {
|
|
const SceneControlDevicesView({super.key});
|
|
|
|
@override
|
|
State<SceneControlDevicesView> createState() =>
|
|
_SceneControlDevicesViewState();
|
|
}
|
|
|
|
class _SceneControlDevicesViewState extends State<SceneControlDevicesView>
|
|
with SingleTickerProviderStateMixin {
|
|
late final TabController _tabController;
|
|
List<RoomModel>? rooms = [];
|
|
|
|
@override
|
|
void initState() {
|
|
rooms = HomeCubit.getInstance().selectedSpace?.rooms;
|
|
if (rooms != null) {
|
|
if (rooms![0].id != '-1') {
|
|
rooms?.insert(
|
|
0,
|
|
RoomModel(
|
|
name: 'All Devices',
|
|
devices: DevicesCubit.getInstance().allDevices,
|
|
id: '-1',
|
|
type: SpaceType.Room,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
_tabController =
|
|
TabController(length: rooms!.length, vsync: this, initialIndex: 0);
|
|
_tabController.addListener(_handleTabSwitched);
|
|
super.initState();
|
|
}
|
|
|
|
void _handleTabSwitched() {
|
|
if (_tabController.indexIsChanging) {
|
|
final value = _tabController.index;
|
|
|
|
/// select tab
|
|
context.read<TabBarBloc>().add(
|
|
TabChanged(selectedIndex: value, roomId: rooms?[value].id ?? ''));
|
|
return;
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
_tabController.dispose();
|
|
_tabController.removeListener(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return DefaultScaffold(
|
|
title: StringsManager.createScene,
|
|
padding: EdgeInsets.zero,
|
|
leading: IconButton(
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
Navigator.pop(context);
|
|
},
|
|
icon: const Icon(
|
|
Icons.arrow_back_ios,
|
|
),
|
|
),
|
|
child: SceneDevicesBody(tabController: _tabController, rooms: rooms),
|
|
);
|
|
}
|
|
}
|