From fe55d0a914e1d9a342b316fd5eb5db9917aa6427 Mon Sep 17 00:00:00 2001 From: mohammad Date: Thu, 21 Nov 2024 16:57:41 +0300 Subject: [PATCH] 4&6scene --- .../6_scene_switch_bloc/6_scene_bloc.dart | 35 ++------- .../6_scene_switch_bloc/6_scene_event.dart | 4 - .../bloc/four_scene_bloc/four_scene_bloc.dart | 5 +- .../6_scene_setting/share_six_scene_page.dart | 12 ++- .../6_scene_setting/six_scene_settings.dart | 73 ++++++++++--------- .../6_scene_switch/six_scene_screen.dart | 1 + .../share_four_scene_page.dart | 12 ++- 7 files changed, 70 insertions(+), 72 deletions(-) diff --git a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart index 4ba5bf0..1a9a224 100644 --- a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart +++ b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart @@ -41,10 +41,10 @@ class SixSceneBloc extends Bloc { on(getSceneByName); on(_selectScene); on(fetchDeviceInfo); - on(_controlDevice); on(saveName); on(_assignDevice); on(_fetchRoomsAndDevices); + on(_onSixSceneInitial); } final TextEditingController nameController = @@ -358,12 +358,14 @@ class SixSceneBloc extends Bloc { value: switchStatus), sixSceneId); deviceStatus.switch_backlight = switchStatus; - if (!response['success']) { - add(const SixSceneInitial()); - } - emit(ChangeSwitchState(isEnable: switchStatus)); - } catch (_) { + add(const SixSceneInitial()); + add(const SexSceneSwitchInitial()); + + emit(ChangeSwitchState(isEnable: switchStatus)); + emit(UpdateState(device: deviceStatus)); + } catch (_) { + emit(const SixSceneFailedState(errorMessage: 'Something went wrong')); } } @@ -455,27 +457,6 @@ class SixSceneBloc extends Bloc { emit(UpdateStateList(groupDevices: groupDevices, devices: devices)); } - void _controlDevice( - ControlDeviceScene event, Emitter emit) async { - emit(SixSceneLoadingState()); - try { - deviceStatus.switch_backlight = !event.backLight!; - emit(UpdateState(device: deviceStatus)); - final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: sixSceneId, - code: 'switch_backlight', - value: !event.backLight!), - sixSceneId); - - if (!response['success']) { - // add(InitialEvent(groupScreen: oneTouchGroup)); - } - } catch (_) { - // add(InitialEvent(groupScreen: oneTouchGroup)); - } - } - bool _validateInputs() { final nameError = fullNameValidator(nameController.text); if (nameError != null) { diff --git a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart index fba85f7..b091103 100644 --- a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart +++ b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart @@ -202,10 +202,6 @@ class AssignDeviceScene extends SixSceneEvent { }); } -class ControlDeviceScene extends SixSceneEvent { - final bool? backLight; - const ControlDeviceScene({this.backLight}); -} class AssignRoomEvent extends SixSceneEvent { final String roomId; diff --git a/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart b/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart index c432bc3..a21c100 100644 --- a/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart +++ b/lib/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart @@ -394,9 +394,8 @@ class FourSceneBloc extends Bloc { value: switchStatus), fourSceneId); deviceStatus.switch_backlight = switchStatus; - if (!response['success']) { - add(const FourSceneInitial()); - } + add(const FourSceneInitial()); + emit(ChangeSwitchState(isEnable: switchStatus)); } catch (_) { add(const FourSceneInitial()); diff --git a/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/share_six_scene_page.dart b/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/share_six_scene_page.dart index 4bc2806..ae38850 100644 --- a/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/share_six_scene_page.dart +++ b/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/share_six_scene_page.dart @@ -1,16 +1,19 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_event.dart'; import 'package:syncrow_app/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/six_scene_model.dart'; +import 'package:syncrow_app/features/menu/view/widgets/manage_home/home_settings.dart'; import 'package:syncrow_app/features/shared_widgets/default_button.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.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/utils/helpers/custom_page_route.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class ShareSixScenePage extends StatelessWidget { @@ -20,6 +23,8 @@ class ShareSixScenePage extends StatelessWidget { @override Widget build(BuildContext context) { + var spaces = HomeCubit.getInstance().spaces; + return DefaultScaffold( title: 'Share Device', child: BlocProvider( @@ -94,7 +99,12 @@ class ShareSixScenePage extends StatelessWidget { child: DefaultButton( backgroundColor: ColorsManager.blueColor1, borderRadius: 50, - onPressed: () {}, + onPressed: () { + Navigator.of(context).push(CustomPageRoute( + builder: (context) => HomeSettingsView( + space: spaces!.first, + ))); + }, child: Text('Add Home Member')), ), ) diff --git a/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/six_scene_settings.dart b/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/six_scene_settings.dart index 9dca157..e06f04d 100644 --- a/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/six_scene_settings.dart +++ b/lib/features/devices/view/widgets/6_scene_switch/6_scene_setting/six_scene_settings.dart @@ -35,7 +35,7 @@ class SixSceneSettings extends StatelessWidget { create: (context) => SixSceneBloc(sixSceneId: device?.uuid ?? '') ..add(const SixSceneInitial()) ..add(const SixSceneInitial()) - ..add(SixSceneInitialInfo()), + ..add(const SixSceneInitialInfo()), child: BlocBuilder( builder: (context, state) { final _bloc = BlocProvider.of(context); @@ -84,14 +84,15 @@ class SixSceneSettings extends StatelessWidget { Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - SizedBox(height: 20), + const SizedBox(height: 20), DefaultContainer( - borderRadius: - BorderRadius.all(Radius.circular(30)), + borderRadius: const BorderRadius.all( + Radius.circular(30)), child: Padding( - padding: EdgeInsets.all(10.0), + padding: const EdgeInsets.all(10.0), child: Padding( - padding: EdgeInsets.only(left: 90), + padding: + const EdgeInsets.only(left: 90), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -104,7 +105,7 @@ class SixSceneSettings extends StatelessWidget { text: _bloc.deviceInfo.name, fontWeight: FontWeight.bold, ), - SizedBox( + const SizedBox( height: 5, ), BodySmall( @@ -112,7 +113,7 @@ class SixSceneSettings extends StatelessWidget { .subspace.subspaceName), ], ), - Icon(Icons.edit_sharp) + const Icon(Icons.edit_sharp) ], ), ), @@ -166,20 +167,20 @@ class SixSceneSettings extends StatelessWidget { text: 'Device Information', icon: Assets.infoIcon, ), - const Divider( - color: ColorsManager.dividerColor, - ), - SettingWidget( - onTap: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => - ShareSixScenePage(device: device!)), - ); - }, - text: 'Tap-to Run and Automation', - icon: Assets.tapRunIcon, - ), + // const Divider( + // color: ColorsManager.dividerColor, + // ), + // SettingWidget( + // onTap: () { + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (context) => + // ShareSixScenePage(device: device!)), + // ); + // }, + // text: 'Tap-to Run and Automation', + // icon: Assets.tapRunIcon, + // ), ], ), ), @@ -225,20 +226,20 @@ class SixSceneSettings extends StatelessWidget { text: 'Share Device', icon: Assets.shareIcon, ), - const Divider( - color: ColorsManager.dividerColor, - ), - SettingWidget( - onTap: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => - SixSceneCreateGroup(device: device!)), - ); - }, - text: 'Create Group', - icon: Assets.createGroupIcon, - ), + // const Divider( + // color: ColorsManager.dividerColor, + // ), + // SettingWidget( + // onTap: () { + // Navigator.of(context).push( + // MaterialPageRoute( + // builder: (context) => + // SixSceneCreateGroup(device: device!)), + // ); + // }, + // text: 'Create Group', + // icon: Assets.createGroupIcon, + // ), const Divider( color: ColorsManager.dividerColor, ), diff --git a/lib/features/devices/view/widgets/6_scene_switch/six_scene_screen.dart b/lib/features/devices/view/widgets/6_scene_switch/six_scene_screen.dart index a374b4f..60ea4c8 100644 --- a/lib/features/devices/view/widgets/6_scene_switch/six_scene_screen.dart +++ b/lib/features/devices/view/widgets/6_scene_switch/six_scene_screen.dart @@ -136,6 +136,7 @@ class SixSceneScreen extends StatelessWidget { child: DefaultContainer( onTap: () { _bloc.add(ChangeSwitchStatusEvent()); + }, child: Column( crossAxisAlignment: diff --git a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/share_four_scene_page.dart b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/share_four_scene_page.dart index 890ef9d..e0db463 100644 --- a/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/share_four_scene_page.dart +++ b/lib/features/devices/view/widgets/four_scene_switch/four_scene_setting/share_four_scene_page.dart @@ -1,15 +1,18 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart'; import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_event.dart'; import 'package:syncrow_app/features/devices/bloc/four_scene_bloc/four_scene_state.dart'; import 'package:syncrow_app/features/devices/model/device_model.dart'; import 'package:syncrow_app/features/devices/model/four_scene_model.dart'; +import 'package:syncrow_app/features/menu/view/widgets/manage_home/home_settings.dart'; import 'package:syncrow_app/features/shared_widgets/default_button.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.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/utils/helpers/custom_page_route.dart'; import 'package:syncrow_app/utils/resource_manager/color_manager.dart'; class ShareFourScenePage extends StatelessWidget { @@ -17,6 +20,8 @@ class ShareFourScenePage extends StatelessWidget { const ShareFourScenePage({super.key, this.device}); @override Widget build(BuildContext context) { + var spaces = HomeCubit.getInstance().spaces; + return DefaultScaffold( title: 'Share Device', child: BlocProvider( @@ -89,7 +94,12 @@ class ShareFourScenePage extends StatelessWidget { child: DefaultButton( backgroundColor: ColorsManager.blueColor1, borderRadius: 50, - onPressed: () {}, + onPressed: () { + Navigator.of(context).push(CustomPageRoute( + builder: (context) => HomeSettingsView( + space: spaces!.first, + ))); + }, child: Text('Add Home Member')), ), )