/// This widget represents a switch for a device on the room page. /// /// This widget displays the icon and name of the device, along with a switch /// to control its state. Tapping on the widget opens the device interface. import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/view/widgets/ACs/acs_view.dart'; import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/wall_sensor_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/presence_sensors/ceiling_sensor_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/smart_door/door_interface.dart'; import 'package:syncrow_app/features/devices/view/widgets/three_gang/three_gang_interface.dart'; import 'package:syncrow_app/features/shared_widgets/custom_switch.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/utils/context_extension.dart'; import 'package:syncrow_app/utils/helpers/custom_page_route.dart'; import 'package:syncrow_app/utils/resource_manager/constants.dart'; class RoomPageSwitch extends StatelessWidget { const RoomPageSwitch({ super.key, required this.device, }); final DeviceModel device; @override Widget build(BuildContext context) { return InkWell( onTap: () { showDeviceInterface(device, context); }, child: DefaultContainer( child: Padding( padding: const EdgeInsets.only(top: 10, right: 10, left: 10), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ SvgPicture.asset( device.icon!, fit: BoxFit.contain, ), CustomSwitch( device: device, ), ], ), Expanded( child: FittedBox( fit: BoxFit.scaleDown, child: BodyLarge( text: device.name ?? "", style: context.bodyLarge.copyWith( fontWeight: FontWeight.bold, height: 0, fontSize: 24, color: Colors.grey, ), ), ), ), ], ), ), ), ); } } /// Shows the device interface based on the product type of the device. /// /// The [device] parameter represents the device model. void showDeviceInterface(DeviceModel device, BuildContext context) { switch (device.productType) { case DeviceType.AC: Navigator.push( context, PageRouteBuilder( pageBuilder: (context, animation1, animation2) => ACsView(deviceModel: device))); // navigateToInterface(ACsView(deviceModel: device), context); break; case DeviceType.WallSensor: navigateToInterface(WallMountedInterface(wallSensor: device), context); break; case DeviceType.CeilingSensor: navigateToInterface(CeilingSensorInterface(ceilingSensor: device), context); break; case DeviceType.Curtain: break; case DeviceType.Blind: break; case DeviceType.DoorLock: navigateToInterface(DoorInterface(doorlock: device), context); break; case DeviceType.Gateway: break; case DeviceType.LightBulb: navigateToInterface(LightInterface(light: device), context); case DeviceType.ThreeGang: Navigator.push( context, PageRouteBuilder( pageBuilder: (context, animation1, animation2) => ThreeGangInterface(gangSwitch: device))); // navigateToInterface(ThreeGangInterface(gangSwitch: device), context); break; default: } } /// Navigates to the specified device interface. /// /// The [interface] parameter represents the widget interface. void navigateToInterface(Widget interface, context) { Navigator.push( context, CustomPageRoute( builder: (context) => BlocProvider( create: (context) => DevicesCubit.getInstance(), child: interface, ), ), ); }