mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 04:19:40 +00:00
112 lines
4.1 KiB
Dart
112 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
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_state.dart';
|
|
import 'package:syncrow_app/features/devices/model/subspace_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_state.dart';
|
|
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
|
|
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
|
|
import 'package:syncrow_app/features/scene/widgets/scene_devices/scene_devices_list.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
|
import 'package:syncrow_app/utils/context_extension.dart';
|
|
import 'package:syncrow_app/utils/resource_manager/color_manager.dart';
|
|
|
|
class SceneDevicesBody extends StatelessWidget {
|
|
const SceneDevicesBody({
|
|
required this.tabController,
|
|
required this.rooms,
|
|
super.key,
|
|
});
|
|
|
|
final TabController tabController;
|
|
final List<SubSpaceModel> rooms;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final routeArguments =
|
|
ModalRoute.of(context)?.settings.arguments as SceneSettingsRouteArguments?;
|
|
final deviceStatusChangesScene = CreateSceneEnum.deviceStatusChanges.name;
|
|
final sceneType = routeArguments?.sceneType;
|
|
final isAutomationDeviceStatus = sceneType == deviceStatusChangesScene;
|
|
|
|
return BlocBuilder<TabBarBloc, TabBarState>(
|
|
builder: (context, state) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TabBar(
|
|
controller: tabController,
|
|
dividerColor: Colors.transparent,
|
|
indicatorColor: Colors.transparent,
|
|
isScrollable: true,
|
|
tabAlignment: TabAlignment.start,
|
|
tabs: rooms.map((e) {
|
|
final isStateTabSelected = state is TabSelected;
|
|
final isSelected = isStateTabSelected && state.roomId == e.id;
|
|
return Tab(
|
|
child: BodyLarge(
|
|
text: e.name ?? '',
|
|
textAlign: TextAlign.start,
|
|
style: context.bodyLarge.copyWith(
|
|
color: isSelected
|
|
? ColorsManager.textPrimaryColor
|
|
: ColorsManager.textPrimaryColor.withValues(
|
|
alpha: 0.2,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}).toList(),
|
|
),
|
|
Expanded(
|
|
child: TabBarView(
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
controller: tabController,
|
|
children: rooms
|
|
.map((e) => _buildRoomTab(e, context, isAutomationDeviceStatus))
|
|
.toList(),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildRoomTab(
|
|
SubSpaceModel room,
|
|
BuildContext context,
|
|
bool isAutomationDeviceStatus,
|
|
) {
|
|
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
|
builder: (context, state) {
|
|
final isLoading = state.loading && state.devices == null;
|
|
final hasData =
|
|
state.devices != null && (state.devices?.isNotEmpty ?? false);
|
|
final hasError = state.error != null;
|
|
|
|
final widgets = <bool, Widget>{
|
|
isLoading: const AppLoadingIndicator(),
|
|
hasError: Center(child: Text('${state.error}')),
|
|
hasData: SceneDevicesList(
|
|
devices: state.devices ?? [],
|
|
isAutomationDeviceStatus: isAutomationDeviceStatus,
|
|
),
|
|
};
|
|
|
|
final validWidgetEntry = widgets.entries.firstWhere(
|
|
(entry) => entry.key == true,
|
|
orElse: () => MapEntry(
|
|
true,
|
|
Center(child: Text('This subspace has no devices')),
|
|
),
|
|
);
|
|
|
|
return validWidgetEntry.value;
|
|
},
|
|
);
|
|
}
|
|
}
|