diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index d26659d..7b17513 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -24,7 +24,6 @@ part 'devices_state.dart'; class DevicesCubit extends Cubit { DevicesCubit._() : super(DevicesInitial()) { - print('device cubit created'); if (HomeCubit.getInstance().selectedSpace != null) { fetchGroups(HomeCubit.getInstance().selectedSpace!.id!); for (var room in HomeCubit.getInstance().selectedSpace!.rooms!) { @@ -256,20 +255,21 @@ class DevicesCubit extends Cubit { code: control.code, )); try { - await DevicesAPI.controlDevice(control).then((value) { + await DevicesAPI.controlDevice(control).then((response) { emitSafe(DeviceControlSuccess( code: control.code, )); - if (value['result'] ?? false) { + if (response['success'] ?? false) { Future.delayed(const Duration(milliseconds: 400), () { getDevicesStatues( - deviceId, - HomeCubit.getInstance().selectedSpace!.rooms!.indexOf( - HomeCubit.getInstance().selectedRoom!, - ), - code: control.code, - ); + deviceId, + HomeCubit.getInstance().selectedSpace!.rooms!.indexOf( + HomeCubit.getInstance().selectedRoom!, + ), + code: control.code); }); + } else { + emitSafe(DeviceControlError('Failed to control the device')); } }); } on DioException catch (e) { @@ -291,8 +291,9 @@ class DevicesCubit extends Cubit { } } - fetchDevicesByRoomId(int roomId) async { + fetchDevicesByRoomId(int? roomId) async { if (_isClosed) return; + if (roomId == null) return; try { emitSafe(GetDevicesLoading()); diff --git a/lib/features/devices/view/widgets/curtains/curtain_view.dart b/lib/features/devices/view/widgets/curtains/curtain_view.dart index 30d7e74..c67b0c6 100644 --- a/lib/features/devices/view/widgets/curtains/curtain_view.dart +++ b/lib/features/devices/view/widgets/curtains/curtain_view.dart @@ -20,13 +20,13 @@ class CurtainView extends StatelessWidget { statusBarColor: ColorsManager.primaryColor.withOpacity(0.5), statusBarIconBrightness: Brightness.light, ), - child: SafeArea( - child: Scaffold( - backgroundColor: ColorsManager.backgroundColor, - extendBodyBehindAppBar: true, - extendBody: true, - appBar: const CategoryViewAppBar(), - body: Container( + child: Scaffold( + backgroundColor: ColorsManager.backgroundColor, + extendBodyBehindAppBar: true, + extendBody: true, + appBar: const CategoryViewAppBar(), + body: SafeArea( + child: Container( width: MediaQuery.sizeOf(context).width, height: MediaQuery.sizeOf(context).height, decoration: const BoxDecoration( diff --git a/lib/features/devices/view/widgets/lights/light_interface.dart b/lib/features/devices/view/widgets/lights/light_interface.dart index e2ae653..2b34853 100644 --- a/lib/features/devices/view/widgets/lights/light_interface.dart +++ b/lib/features/devices/view/widgets/lights/light_interface.dart @@ -24,31 +24,29 @@ class LightInterface extends StatelessWidget { statusBarColor: ColorsManager.primaryColor.withOpacity(0.5), statusBarIconBrightness: Brightness.light, ), - child: SafeArea( - child: Scaffold( - backgroundColor: ColorsManager.backgroundColor, - extendBodyBehindAppBar: true, - extendBody: true, - appBar: AppBar( - backgroundColor: Colors.transparent, - centerTitle: true, - title: BodyLarge( - text: light.name ?? "", - fontColor: ColorsManager.primaryColor, - fontWeight: FontsManager.bold, - ), + child: Scaffold( + backgroundColor: ColorsManager.backgroundColor, + extendBodyBehindAppBar: true, + extendBody: true, + appBar: AppBar( + backgroundColor: Colors.transparent, + centerTitle: true, + title: BodyLarge( + text: light.name ?? "", + fontColor: ColorsManager.primaryColor, + fontWeight: FontsManager.bold, ), - body: Padding( - padding: const EdgeInsets.only(top: 70, right: 20, left: 20), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - LightInterfaceSwitch(light: light), - LightInterfaceContols(light: light), - const LightInterfaceTimer(), - ], - ), + ), + body: Padding( + padding: const EdgeInsets.only(top: 70, right: 20, left: 20), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + LightInterfaceSwitch(light: light), + LightInterfaceContols(light: light), + const LightInterfaceTimer(), + ], ), ), ), diff --git a/lib/features/devices/view/widgets/wizard_switches.dart b/lib/features/devices/view/widgets/wizard_switches.dart index 6dc6d93..7d5de2b 100644 --- a/lib/features/devices/view/widgets/wizard_switches.dart +++ b/lib/features/devices/view/widgets/wizard_switches.dart @@ -34,7 +34,7 @@ class WizartSwitches extends StatelessWidget { itemBuilder: (_, index) { return InkWell( onTap: () { - DevicesCubit.getInstance().selectCategory(index); + // DevicesCubit.getInstance().selectCategory(index); //Navigate to the chosen category view without animation Navigator.push(context,