import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; import 'package:syncrow_app/features/devices/bloc/devices_cubit.dart'; import 'package:syncrow_app/features/devices/model/device_control_model.dart'; import 'package:syncrow_app/generated/assets.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class LightSwitch extends StatelessWidget { const LightSwitch({ super.key, required this.control, }); final DeviceControlModel control; @override Widget build(BuildContext context) { return BlocBuilder( builder: (context, state) { return state is DeviceControlLoading ? const CircularProgressIndicator() : InkWell( overlayColor: MaterialStateProperty.all(Colors.transparent), onTap: () { DevicesCubit.get(context) .deviceControl(control) .then((value) { print('Device control response: $value'); if (control.value ?? true) { control.value = false; } else { control.value = true; } }); }, child: Stack( alignment: !control.value! ? Alignment.topCenter : Alignment.bottomCenter, children: [ Container( decoration: BoxDecoration( borderRadius: const BorderRadius.all(Radius.circular(100.0)), color: !control.value! ? ColorsManager.primaryColorWithOpacity : ColorsManager.switchOffColor, ), width: 60, height: 115, ), Padding( padding: const EdgeInsets.all(5.0), child: SizedBox.square( dimension: 60, child: SvgPicture.asset( !control.value! ? Assets.iconsLightSwitchOn : Assets.iconsLightSwitchOff, fit: BoxFit.fill, ), ), ), ], ), ); }, ); } }