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 5ce176b..ca63e87 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 @@ -167,24 +167,8 @@ class SixSceneBloc extends Bloc { } } - Future saveName( - SaveNameEvent event, Emitter emit) async { - if (_validateInputs()) return; - try { - add(const ChangeNameEvent(value: false)); - isSaving = true; - emit(SixSceneLoadingState()); - var response = await DevicesAPI.putDeviceName( - deviceId: sixSceneId, deviceName: nameController.text); - add(const SixSceneInitialInfo()); - CustomSnackBar.displaySnackBar('Save Successfully'); - emit(SaveState()); - } catch (e) { - emit(SixSceneFailedState(errorMessage: e.toString())); - } finally { - isSaving = false; - } - } +//============================ fitch devise info and status ======================= +///////////////////////////////////////////////////////////////////////////////////// Future fetchDeviceInfo( SixSceneInitialInfo event, Emitter emit) async { @@ -219,6 +203,9 @@ class SixSceneBloc extends Bloc { } } + //============================ assign Scene ======================= +///////////////////////////////////////////////////////////////////////////////////// + String selectedFormApiSceneId = ''; void getSceneByName( @@ -332,44 +319,6 @@ class SixSceneBloc extends Bloc { DeviceReport recordGroups = DeviceReport(startTime: '0', endTime: '0', data: []); - final List faqQuestions = [ - SixSceneQuestionModel( - id: 1, - question: 'How does an SOS emergency button work?', - answer: - 'The SOS emergency button sends an alert to your contacts when pressed.', - ), - SixSceneQuestionModel( - id: 2, - question: 'How long will an SOS alarm persist?', - answer: - 'The SOS alarm will persist until it is manually turned off or after a set time.', - ), - SixSceneQuestionModel( - id: 3, - question: 'What should I do if the SOS button is unresponsive?', - answer: 'Try restarting the device. If it persists, contact support.', - ), - SixSceneQuestionModel( - id: 4, - question: 'Can I use the SOS feature without a network connection?', - answer: - 'No, a network connection is required to send the alert to your contacts.', - ), - SixSceneQuestionModel( - id: 5, - question: 'How often should I check the SOS battery?', - answer: - 'Check the SOS battery at least once a month to ensure it is operational.', - ), - ]; - - Future _onSixSceneInitial( - SixSceneInitialQuestion event, Emitter emit) async { - emit(SixSceneLoadingState()); - emit(FaqLoadedState(filteredFaqQuestions: faqQuestions)); - } - List allDevices = []; bool switchStatus = true; @@ -430,7 +379,7 @@ class SixSceneBloc extends Bloc { filteredScenes = event.query.isEmpty ? allScenes : allScenes.where((scene) { - final sceneName = scene.name?.toLowerCase() ?? ''; + final sceneName = scene.name.toLowerCase() ?? ''; return sceneName.contains(event.query.toLowerCase()); }).toList(); emit(SearchResultsState()); @@ -456,6 +405,7 @@ class SixSceneBloc extends Bloc { } } +//============================= group settings ================================= //addDevicesIcon List groupDevices = [ GroupDevicesModel( @@ -488,6 +438,97 @@ class SixSceneBloc extends Bloc { emit(UpdateStateList(groupDevices: groupDevices, devices: devices)); } + //======================= update device functions ============================ + ////////////////////////////////////////////////////////////////////////////// + + bool enableUpdate = false; + + void _toggleUpdate( + ToggleUpdateEvent event, Emitter emit) async { + try { + emit(SixSceneLoadingState()); + enableUpdate = event.isUpdateEnabled!; + emit(SaveState()); + } catch (e) { + emit(const SixSceneFailedState(errorMessage: 'Something went wrong')); + } + } + +//======================= q&a and questions ==================================== +//////////////////////////////////////////////////////////////////////////////// + bool isHelpful = false; + + void _toggleHelpful( + ToggleHelpfulEvent event, Emitter emit) async { + try { + emit(SixSceneLoadingState()); + isHelpful = event.isHelpful!; + emit(SaveState()); + } catch (e) { + emit(const SixSceneFailedState(errorMessage: 'Something went wrong')); + } + } + + final List faqQuestions = [ + SixSceneQuestionModel( + id: 1, + question: 'How does an SOS emergency button work?', + answer: + 'The SOS emergency button sends an alert to your contacts when pressed.', + ), + SixSceneQuestionModel( + id: 2, + question: 'How long will an SOS alarm persist?', + answer: + 'The SOS alarm will persist until it is manually turned off or after a set time.', + ), + SixSceneQuestionModel( + id: 3, + question: 'What should I do if the SOS button is unresponsive?', + answer: 'Try restarting the device. If it persists, contact support.', + ), + SixSceneQuestionModel( + id: 4, + question: 'Can I use the SOS feature without a network connection?', + answer: + 'No, a network connection is required to send the alert to your contacts.', + ), + SixSceneQuestionModel( + id: 5, + question: 'How often should I check the SOS battery?', + answer: + 'Check the SOS battery at least once a month to ensure it is operational.', + ), + ]; + + Future _onSixSceneInitial( + SixSceneInitialQuestion event, Emitter emit) async { + emit(SixSceneLoadingState()); + emit(FaqLoadedState(filteredFaqQuestions: faqQuestions)); + } + + //=========================== name setting =================================== + //////////////////////////////////////////////////////////////////////////////// + + Future saveName( + SaveNameEvent event, Emitter emit) async { + if (_validateInputs()) return; + try { + add(const ChangeNameEvent(value: false)); + isSaving = true; + emit(SixSceneLoadingState()); + var response = await DevicesAPI.putDeviceName( + deviceId: sixSceneId, deviceName: nameController.text); + add(const SixSceneInitialInfo()); + CustomSnackBar.displaySnackBar('Save Successfully'); + emit(SaveState()); + } catch (e) { + emit(SixSceneFailedState(errorMessage: e.toString())); + } finally { + isSaving = false; + } + } + bool _validateInputs() { final nameError = fullNameValidator(nameController.text); if (nameError != null) { @@ -508,30 +549,4 @@ class SixSceneBloc extends Bloc { } return null; } - - bool enableUpdate = false; - - void _toggleUpdate( - ToggleUpdateEvent event, Emitter emit) async { - try { - emit(SixSceneLoadingState()); - enableUpdate = event.isUpdateEnabled!; - emit(SaveState()); - } catch (e) { - emit(const SixSceneFailedState(errorMessage: 'Something went wrong')); - } - } - - bool isHelpful = false; - - void _toggleHelpful( - ToggleHelpfulEvent event, Emitter emit) async { - try { - emit(SixSceneLoadingState()); - isHelpful = event.isHelpful!; - emit(SaveState()); - } catch (e) { - emit(const SixSceneFailedState(errorMessage: 'Something went wrong')); - } - } } 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 5600510..7f95867 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 @@ -10,21 +10,6 @@ abstract class SixSceneEvent extends Equatable { List get props => []; } -class SixSceneLoading extends SixSceneEvent {} - -class SixSceneSwitch extends SixSceneEvent { - final String switchD; - final String deviceId; - final String productId; - const SixSceneSwitch( - {required this.switchD, this.deviceId = '', this.productId = ''}); - - @override - List get props => [switchD, deviceId, productId]; -} - -class SixSceneUpdated extends SixSceneEvent {} - class GetSceneBySwitchName extends SixSceneEvent { final String? switchName; @@ -47,19 +32,6 @@ class SexSceneSwitchInitial extends SixSceneEvent { const SexSceneSwitchInitial(); } -class ReportLogsInitial extends SixSceneEvent { - const ReportLogsInitial(); -} - -class SixSceneChangeStatus extends SixSceneEvent {} - -class GetCounterEvent extends SixSceneEvent { - final String deviceCode; - const GetCounterEvent({required this.deviceCode}); - @override - List get props => [deviceCode]; -} - class ToggleEnableAlarmEvent extends SixSceneEvent { final bool isLowBatteryEnabled; @@ -78,44 +50,6 @@ class ToggleNotificationEvent extends SixSceneEvent { List get props => [isClosingEnabled]; } -class ToggleSixSceneAlarmEvent extends SixSceneEvent { - final bool isSixSceneAlarmEnabled; - - const ToggleSixSceneAlarmEvent(this.isSixSceneAlarmEnabled); - - @override - List get props => [isSixSceneAlarmEnabled]; -} - -class SetCounterValue extends SixSceneEvent { - final Duration duration; - final String deviceCode; - const SetCounterValue({required this.duration, required this.deviceCode}); - @override - List get props => [duration, deviceCode]; -} - -class StartTimer extends SixSceneEvent { - final int duration; - - const StartTimer(this.duration); - - @override - List get props => [duration]; -} - -class TickTimer extends SixSceneEvent { - final int remainingTime; - - const TickTimer(this.remainingTime); - - @override - List get props => [remainingTime]; -} - -class StopTimer extends SixSceneEvent {} - -class OnClose extends SixSceneEvent {} class DeleteDeviceEvent extends SixSceneEvent {} class ChangeNameEvent extends SixSceneEvent { @@ -182,14 +116,14 @@ class SelectOptionEvent extends SixSceneEvent { class AddDeviceToGroup extends SixSceneEvent { final GroupDevicesModel device; final String icon; - AddDeviceToGroup(this.device, this.icon); + const AddDeviceToGroup(this.device, this.icon); } class RemoveDeviceFromGroup extends SixSceneEvent { final GroupDevicesModel device; final String icon; - RemoveDeviceFromGroup(this.device, this.icon); + const RemoveDeviceFromGroup(this.device, this.icon); } class AssignDeviceScene extends SixSceneEvent { @@ -203,7 +137,6 @@ class AssignDeviceScene extends SixSceneEvent { }); } - class AssignRoomEvent extends SixSceneEvent { final String roomId; final SpaceModel unit; @@ -223,15 +156,12 @@ class AssignRoomEvent extends SixSceneEvent { ]; } - - class ToggleUpdateEvent extends SixSceneEvent { final bool? isUpdateEnabled; const ToggleUpdateEvent({this.isUpdateEnabled}); } - class ToggleHelpfulEvent extends SixSceneEvent { final bool? isHelpful; const ToggleHelpfulEvent({this.isHelpful}); -} \ No newline at end of file +} diff --git a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart index 01f72b0..0a4ed56 100644 --- a/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart +++ b/lib/features/devices/bloc/6_scene_switch_bloc/6_scene_state.dart @@ -14,12 +14,9 @@ class SixSceneState extends Equatable { List get props => []; } -class SixSceneInitialState extends SixSceneState {} - class SixSceneLoadingState extends SixSceneState {} -class SaveState extends SixSceneState {} -class SixSceState extends SixSceneState {} +class SaveState extends SixSceneState {} class UpdateStateList extends SixSceneState { final List groupDevices; @@ -55,13 +52,13 @@ class LoadingNewSate extends SixSceneState { class NameEditingState extends SixSceneState { final bool editName; - NameEditingState({required this.editName}); + const NameEditingState({required this.editName}); } class FaqLoadedState extends SixSceneState { final List filteredFaqQuestions; - FaqLoadedState({this.filteredFaqQuestions = const []}); + const FaqLoadedState({this.filteredFaqQuestions = const []}); } class FaqSearchState extends SixSceneState { @@ -95,8 +92,6 @@ class SceneLoaded extends SixSceneState { {this.loadingSceneId, this.loadingStates = const {}}); } -class SelectedSceneState extends SixSceneState {} - class SearchResultsState extends SixSceneState {} class SaveSelectionSuccessState extends SixSceneState {} @@ -105,7 +100,7 @@ class OptionSelectedState extends SixSceneState { final String selectedOption; final bool hasSelectionChanged; - OptionSelectedState({ + const OptionSelectedState({ required this.selectedOption, required this.hasSelectionChanged, }); @@ -117,7 +112,7 @@ class OptionSelectedState extends SixSceneState { class SceneSelectionUpdatedState extends SixSceneState { final String selectedSceneId; - SceneSelectionUpdatedState({required this.selectedSceneId}); + const SceneSelectionUpdatedState({required this.selectedSceneId}); } class LoadingDeviceInfo extends SixSceneState { 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 4a66410..95a5132 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 @@ -110,7 +110,7 @@ class FourSceneBloc extends Bloc { ), ); -//============================ get Scene and assign scene ===================== +//============================ get Scene and assign scene ======================= String selectedFormApiSceneId = ''; String selectedSceneId = ''; diff --git a/lib/features/devices/view/widgets/sos/sos_records_screen.dart b/lib/features/devices/view/widgets/sos/sos_records_screen.dart index e459226..c85c3a8 100644 --- a/lib/features/devices/view/widgets/sos/sos_records_screen.dart +++ b/lib/features/devices/view/widgets/sos/sos_records_screen.dart @@ -5,7 +5,6 @@ import 'package:intl/intl.dart'; import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_bloc.dart'; import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_event.dart'; import 'package:syncrow_app/features/devices/bloc/sos_bloc/sos_state.dart'; - import 'package:syncrow_app/features/devices/model/device_report_model.dart'; import 'package:syncrow_app/features/shared_widgets/default_container.dart'; import 'package:syncrow_app/features/shared_widgets/default_scaffold.dart'; diff --git a/lib/features/devices/view/widgets/sos/sos_setting/delete_dialog.dart b/lib/features/devices/view/widgets/sos/sos_setting/delete_dialog.dart deleted file mode 100644 index e69de29..0000000