mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-16 18:16:21 +00:00
129 lines
5.0 KiB
Dart
129 lines
5.0 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/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_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/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 TabController tabController,
|
|
required this.rooms,
|
|
}) : _tabController = tabController;
|
|
|
|
final TabController _tabController;
|
|
final List<RoomModel>? rooms;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final isAutomationDeviceStatus = ((ModalRoute.of(context)
|
|
?.settings
|
|
.arguments as SceneSettingsRouteArguments?)
|
|
?.sceneType ==
|
|
CreateSceneEnum.deviceStatusChanges.name);
|
|
return BlocBuilder<TabBarBloc, TabBarState>(
|
|
builder: (context, tabState) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TabBar(
|
|
controller: _tabController,
|
|
dividerColor: Colors.transparent,
|
|
indicatorColor: Colors.transparent,
|
|
tabs: [
|
|
...rooms!.map((e) => Tab(
|
|
child: BodyLarge(
|
|
text: e.name ?? '',
|
|
textAlign: TextAlign.start,
|
|
style: context.bodyLarge.copyWith(
|
|
color: (tabState is TabSelected) &&
|
|
tabState.roomId == e.id
|
|
? ColorsManager.textPrimaryColor
|
|
: ColorsManager.textPrimaryColor.withOpacity(0.2),
|
|
),
|
|
),
|
|
)),
|
|
],
|
|
isScrollable: true,
|
|
tabAlignment: TabAlignment.start,
|
|
),
|
|
Expanded(
|
|
child: TabBarView(
|
|
controller: _tabController,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
children: rooms!
|
|
.map((e) =>
|
|
_buildRoomTab(e, context, isAutomationDeviceStatus))
|
|
.toList(),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildRoomTab(
|
|
RoomModel room, BuildContext context, bool isAutomationDeviceStatus) {
|
|
return BlocBuilder<DeviceManagerBloc, DeviceManagerState>(
|
|
builder: (context, state) {
|
|
if (state.loading && state.devices == null) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
} 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 Center(child: Text(state.error!));
|
|
} else {
|
|
return const SizedBox();
|
|
}
|
|
},
|
|
);
|
|
}
|
|
}
|