Files
syncrow-app/lib/features/devices/view/widgets/room_page_switch.dart
2024-10-06 16:48:17 +03:00

218 lines
8.0 KiB
Dart

/// 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_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/curtains/curtain_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/door_sensor/door_sensor_screen.dart';
import 'package:syncrow_app/features/devices/view/widgets/garage_door/garage_door_screen.dart';
import 'package:syncrow_app/features/devices/view/widgets/gateway/gateway_view.dart';
import 'package:syncrow_app/features/devices/view/widgets/lights/light_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/one_gang/one_gang_Interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/one_touch/one_touch_screen.dart';
import 'package:syncrow_app/features/devices/view/widgets/three_touch/three_touch_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/two_gang/two_gang_Interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/two_touch/two_touch_Interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/wall_sensor/wall_sensor_interface.dart';
import 'package:syncrow_app/features/devices/view/widgets/ceiling_sensor/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/devices/view/widgets/water_heater/water_heater_page.dart';
import 'package:syncrow_app/features/shared_widgets/default_container.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 GestureDetector(
onTap: () {
showDeviceInterface(device, context);
},
child: DefaultContainer(
padding: const EdgeInsets.all(15),
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,
// ),
],
),
Flexible(
child: FittedBox(
child: Text(
device.type ?? "",
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: context.bodyLarge.copyWith(
fontWeight: FontWeight.bold,
fontSize: 20,
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);
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
WallMountedInterface(deviceModel: device)));
break;
case DeviceType.CeilingSensor:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
CeilingSensorInterface(ceilingSensor: device)));
// navigateToInterface(CeilingSensorInterface(ceilingSensor: device), context);
break;
case DeviceType.Curtain:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => CurtainView(
curtain: device,
)));
break;
case DeviceType.Blind:
break;
case DeviceType.DoorLock:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
DoorInterface(doorLock: device)));
// navigateToInterface(DoorInterface(doorlock: device), context);
break;
case DeviceType.Gateway:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
GateWayView(gatewayObj: device)));
break;
case DeviceType.LightBulb:
navigateToInterface(LightInterface(light: device), context);
case DeviceType.OneGang:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
OneGangInterface(gangSwitch: device)));
case DeviceType.TwoGang:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
TwoGangInterface(gangSwitch: device)));
case DeviceType.ThreeGang:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
ThreeGangInterface(gangSwitch: device)));
case DeviceType.WH:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
WaterHeaterPage(device: device)));
case DeviceType.DS:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
DoorSensorScreen(device: device)));
case DeviceType.OneTouch:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
OneTouchScreen(device: device)));
case DeviceType.TowTouch:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
TwoTouchInterface(touchSwitch: device)));
case DeviceType.ThreeTouch:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
ThreeTouchInterface(touchSwitch: device)));
case DeviceType.GarageDoor:
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) =>
GarageDoorScreen(device: device)));
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,
),
),
);
}