mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 07:59:39 +00:00
134 lines
5.2 KiB
Dart
134 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:flutter_svg/flutter_svg.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_list_tile.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/app_loading_indicator.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/default_container.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_large.dart';
|
|
import 'package:syncrow_app/features/shared_widgets/text_widgets/body_medium.dart';
|
|
import 'package:syncrow_app/navigation/routing_constants.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({
|
|
super.key,
|
|
required this.tabController,
|
|
required this.rooms,
|
|
});
|
|
|
|
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,
|
|
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(),
|
|
isScrollable: true,
|
|
tabAlignment: TabAlignment.start,
|
|
),
|
|
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) {
|
|
if (state.loading && state.devices == null) {
|
|
return const AppLoadingIndicator();
|
|
} else if (state.devices != null && state.devices!.isNotEmpty) {
|
|
return ListView.builder(
|
|
itemCount: state.devices!.length,
|
|
itemBuilder: (context, index) {
|
|
final device = state.devices?[index];
|
|
return DefaultContainer(
|
|
child: SceneListTile(
|
|
minLeadingWidth: 40,
|
|
leadingWidget: SvgPicture.asset(device?.icon ?? ''),
|
|
titleWidget: BodyMedium(
|
|
text: device?.name ?? '',
|
|
style: context.titleSmall.copyWith(
|
|
color: ColorsManager.secondaryTextColor,
|
|
fontWeight: FontWeight.w400,
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
trailingWidget: const Icon(
|
|
Icons.arrow_forward_ios_rounded,
|
|
color: ColorsManager.greyColor,
|
|
size: 16,
|
|
),
|
|
onPressed: () => Navigator.pushNamed(
|
|
context,
|
|
Routes.deviceFunctionsRoute,
|
|
arguments: {
|
|
"device": device,
|
|
"isAutomationDeviceStatus": isAutomationDeviceStatus
|
|
},
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
} else if (state.error != null) {
|
|
return const Center(child: Text('Something went wrong'));
|
|
} else {
|
|
return const SizedBox();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|