diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index ad16c69..2d31248 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -18,6 +18,7 @@ android:exported="true" android:launchMode="singleTop" android:theme="@style/LaunchTheme" + android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" android:windowSoftInputMode="adjustResize"> diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index dc5d7bf..0e5c500 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -553,7 +553,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 48V27SBR8J; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -563,7 +563,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.5; PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -745,7 +745,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 48V27SBR8J; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -755,7 +755,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.5; PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -775,7 +775,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 48V27SBR8J; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -785,7 +785,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.5; PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -862,7 +862,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 48V27SBR8J; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -872,7 +872,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.5; PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -965,7 +965,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 48V27SBR8J; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -975,7 +975,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.5; PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1063,7 +1063,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 20; + CURRENT_PROJECT_VERSION = 31; DEVELOPMENT_TEAM = 48V27SBR8J; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -1073,7 +1073,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.0.2; + MARKETING_VERSION = 1.0.5; PRODUCT_BUNDLE_IDENTIFIER = com.example.syncrow.app; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/ios/Runner/Info.plist b/ios/Runner/Info.plist index 36d1814..0169fa9 100644 --- a/ios/Runner/Info.plist +++ b/ios/Runner/Info.plist @@ -2,8 +2,6 @@ - NSPhotoLibraryUsageDescription - We need access to your photo library to allow you to select and upload photos. CADisableMinimumFrameDurationOnPhone CFBundleDevelopmentRegion @@ -28,6 +26,8 @@ $(FLUTTER_BUILD_NUMBER) LSRequiresIPhoneOS + NSPhotoLibraryUsageDescription + We need access to your photo library to allow you to select and upload photos. UIApplicationSupportsIndirectInputEvents UILaunchStoryboardName @@ -36,10 +36,7 @@ Main UISupportedInterfaceOrientations - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown diff --git a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart index af74e8d..04f434c 100644 --- a/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart +++ b/lib/features/devices/bloc/three_gang_bloc/three_gang_bloc.dart @@ -31,8 +31,7 @@ class ThreeGangBloc extends Bloc { List groupThreeGangList = []; bool allSwitchesOn = true; - ThreeGangBloc({required this.threeGangId, required this.switchCode}) - : super(InitialState()) { + ThreeGangBloc({required this.threeGangId, required this.switchCode}) : super(InitialState()) { on(_fetchThreeGangStatus); on(_threeGangUpdated); on(_changeFirstSwitch); @@ -58,8 +57,7 @@ class ThreeGangBloc extends Bloc { on(toggleCreateSchedule); } - void _fetchThreeGangStatus( - InitialEvent event, Emitter emit) async { + void _fetchThreeGangStatus(InitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { threeGangGroup = event.groupScreen; @@ -71,8 +69,7 @@ class ThreeGangBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', '3G'); for (int i = 0; i < devicesList.length; i++) { - var response = - await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); + var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); List statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); @@ -89,16 +86,13 @@ class ThreeGangBloc extends Bloc { if (groupThreeGangList.isNotEmpty) { groupThreeGangList.firstWhere((element) { - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesOn = false; } return true; }); } - emit(UpdateGroupState( - threeGangList: groupThreeGangList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesOn)); } else { var response = await DevicesAPI.getDeviceStatus(threeGangId); List statusModelList = []; @@ -117,21 +111,18 @@ class ThreeGangBloc extends Bloc { _listenToChanges() { try { - DatabaseReference ref = - FirebaseDatabase.instance.ref('device-status/$threeGangId'); + DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeGangId'); Stream stream = ref.onValue; stream.listen((DatabaseEvent event) async { if (_timer != null) { await Future.delayed(const Duration(seconds: 2)); } - Map usersMap = - event.snapshot.value as Map; + Map usersMap = event.snapshot.value as Map; List statusList = []; usersMap['status'].forEach((element) { - statusList - .add(StatusModel(code: element['code'], value: element['value'])); + statusList.add(StatusModel(code: element['code'], value: element['value'])); }); deviceStatus = ThreeGangModel.fromJson(statusList); @@ -146,8 +137,7 @@ class ThreeGangBloc extends Bloc { emit(UpdateState(threeGangModel: deviceStatus)); } - void _changeFirstSwitch( - ChangeFirstSwitchStatusEvent event, Emitter emit) async { + void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(threeGangModel: deviceStatus)); try { if (threeGangGroup) { @@ -156,14 +146,11 @@ class ThreeGangBloc extends Bloc { if (element.deviceId == event.deviceId) { element.firstSwitch = !event.value; } - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesValue = false; } }); - emit(UpdateGroupState( - threeGangList: groupThreeGangList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue)); } else { deviceStatus.firstSwitch = !event.value; emit(UpdateState(threeGangModel: deviceStatus)); @@ -173,7 +160,7 @@ class ThreeGangBloc extends Bloc { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: threeGangGroup ? event.deviceId : threeGangId, @@ -200,14 +187,11 @@ class ThreeGangBloc extends Bloc { if (element.deviceId == event.deviceId) { element.secondSwitch = !event.value; } - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesValue = false; } }); - emit(UpdateGroupState( - threeGangList: groupThreeGangList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue)); } else { deviceStatus.secondSwitch = !event.value; emit(UpdateState(threeGangModel: deviceStatus)); @@ -216,7 +200,7 @@ class ThreeGangBloc extends Bloc { if (_timer != null) { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: threeGangGroup ? event.deviceId : threeGangId, @@ -233,8 +217,7 @@ class ThreeGangBloc extends Bloc { } } - void _changeThirdSwitch( - ChangeThirdSwitchStatusEvent event, Emitter emit) async { + void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(threeGangModel: deviceStatus)); try { if (threeGangGroup) { @@ -243,14 +226,11 @@ class ThreeGangBloc extends Bloc { if (element.deviceId == event.deviceId) { element.thirdSwitch = !event.value; } - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesValue = false; } }); - emit(UpdateGroupState( - threeGangList: groupThreeGangList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: allSwitchesValue)); } else { deviceStatus.thirdSwitch = !event.value; emit(UpdateState(threeGangModel: deviceStatus)); @@ -260,7 +240,7 @@ class ThreeGangBloc extends Bloc { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: threeGangGroup ? event.deviceId : threeGangId, @@ -289,21 +269,15 @@ class ThreeGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeGangId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch), threeGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeGangId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch), threeGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeGangId, - code: 'switch_3', - value: deviceStatus.thirdSwitch), + deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch), threeGangId), ]); @@ -329,21 +303,15 @@ class ThreeGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeGangId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: threeGangId, code: 'switch_1', value: deviceStatus.firstSwitch), threeGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeGangId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: threeGangId, code: 'switch_2', value: deviceStatus.secondSwitch), threeGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeGangId, - code: 'switch_3', - value: deviceStatus.thirdSwitch), + deviceId: threeGangId, code: 'switch_3', value: deviceStatus.thirdSwitch), threeGangId), ]); @@ -365,11 +333,9 @@ class ThreeGangBloc extends Bloc { groupThreeGangList[i].secondSwitch = true; groupThreeGangList[i].thirdSwitch = true; } - emit(UpdateGroupState( - threeGangList: groupThreeGangList, allSwitches: true)); + emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: true)); - List allDeviceIds = - groupThreeGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -399,8 +365,7 @@ class ThreeGangBloc extends Bloc { } } - void _groupAllOff( - GroupAllOffEvent event, Emitter emit) async { + void _groupAllOff(GroupAllOffEvent event, Emitter emit) async { emit(LoadingNewSate(threeGangModel: deviceStatus)); try { for (int i = 0; i < groupThreeGangList.length; i++) { @@ -408,10 +373,8 @@ class ThreeGangBloc extends Bloc { groupThreeGangList[i].secondSwitch = false; groupThreeGangList[i].thirdSwitch = false; } - emit(UpdateGroupState( - threeGangList: groupThreeGangList, allSwitches: false)); - List allDeviceIds = - groupThreeGangList.map((device) => device.deviceId).toList(); + emit(UpdateGroupState(threeGangList: groupThreeGangList, allSwitches: false)); + List allDeviceIds = groupThreeGangList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -441,20 +404,17 @@ class ThreeGangBloc extends Bloc { } } - void _changeSliding( - ChangeSlidingSegment event, Emitter emit) async { + void _changeSliding(ChangeSlidingSegment event, Emitter emit) async { emit(ChangeSlidingSegmentState(value: event.value)); } - void _setCounterValue( - SetCounterValue event, Emitter emit) async { + void _setCounterValue(SetCounterValue event, Emitter emit) async { emit(LoadingNewSate(threeGangModel: deviceStatus)); int seconds = 0; try { seconds = event.duration.inSeconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: threeGangId, code: event.deviceCode, value: seconds), + DeviceControlModel(deviceId: threeGangId, code: event.deviceCode, value: seconds), threeGangId); if (response['success'] ?? false) { @@ -481,8 +441,7 @@ class ThreeGangBloc extends Bloc { } } - void _getCounterValue( - GetCounterEvent event, Emitter emit) async { + void _getCounterValue(GetCounterEvent event, Emitter emit) async { emit(LoadingInitialState()); try { var response = await DevicesAPI.getDeviceStatus(threeGangId); @@ -592,8 +551,7 @@ class ThreeGangBloc extends Bloc { deviceId: threeGangId, ); List jsonData = response; - listSchedule = - jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); + listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); emit(InitialState()); } on DioException catch (e) { final errorData = e.response!.data; @@ -604,13 +562,12 @@ class ThreeGangBloc extends Bloc { int? getTimeStampWithoutSeconds(DateTime? dateTime) { if (dateTime == null) return null; - DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month, - dateTime.day, dateTime.hour, dateTime.minute); + DateTime dateTimeWithoutSeconds = + DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - Future toggleChange( - ToggleScheduleEvent event, Emitter emit) async { + Future toggleChange(ToggleScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.changeSchedule( @@ -629,8 +586,7 @@ class ThreeGangBloc extends Bloc { } } - Future deleteSchedule( - DeleteScheduleEvent event, Emitter emit) async { + Future deleteSchedule(DeleteScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.deleteSchedule( @@ -650,15 +606,13 @@ class ThreeGangBloc extends Bloc { } } - void toggleSelectedIndex( - ToggleSelectedEvent event, Emitter emit) { + void toggleSelectedIndex(ToggleSelectedEvent event, Emitter emit) { emit(LoadingInitialState()); selectedTabIndex = event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } - void toggleCreateSchedule( - ToggleCreateScheduleEvent event, Emitter emit) { + void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { emit(LoadingInitialState()); createSchedule = !createSchedule; selectedDays.clear(); diff --git a/lib/features/devices/bloc/three_touch_bloc/three_touch_bloc.dart b/lib/features/devices/bloc/three_touch_bloc/three_touch_bloc.dart index ed369eb..beec442 100644 --- a/lib/features/devices/bloc/three_touch_bloc/three_touch_bloc.dart +++ b/lib/features/devices/bloc/three_touch_bloc/three_touch_bloc.dart @@ -38,8 +38,7 @@ class ThreeTouchBloc extends Bloc { List groupThreeTouchList = []; bool allSwitchesOn = true; - ThreeTouchBloc({required this.threeTouchId, required this.switchCode}) - : super(InitialState()) { + ThreeTouchBloc({required this.threeTouchId, required this.switchCode}) : super(InitialState()) { on(_fetchThreeTouchStatus); on(_threeTouchUpdated); on(_changeFirstSwitch); @@ -64,8 +63,7 @@ class ThreeTouchBloc extends Bloc { on(_changeStatus); } - void _fetchThreeTouchStatus( - InitialEvent event, Emitter emit) async { + void _fetchThreeTouchStatus(InitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { threeTouchGroup = event.groupScreen; @@ -77,8 +75,7 @@ class ThreeTouchBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', '3GT'); for (int i = 0; i < devicesList.length; i++) { - var response = - await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); + var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); List statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); @@ -95,16 +92,13 @@ class ThreeTouchBloc extends Bloc { if (groupThreeTouchList.isNotEmpty) { groupThreeTouchList.firstWhere((element) { - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesOn = false; } return true; }); } - emit(UpdateGroupState( - threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesOn)); } else { var response = await DevicesAPI.getDeviceStatus(threeTouchId); List statusModelList = []; @@ -123,21 +117,18 @@ class ThreeTouchBloc extends Bloc { _listenToChanges() { try { - DatabaseReference ref = - FirebaseDatabase.instance.ref('device-status/$threeTouchId'); + DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$threeTouchId'); Stream stream = ref.onValue; stream.listen((DatabaseEvent event) async { if (_timer != null) { await Future.delayed(const Duration(seconds: 2)); } - Map usersMap = - event.snapshot.value as Map; + Map usersMap = event.snapshot.value as Map; List statusList = []; usersMap['status'].forEach((element) { - statusList - .add(StatusModel(code: element['code'], value: element['value'])); + statusList.add(StatusModel(code: element['code'], value: element['value'])); }); deviceStatus = ThreeTouchModel.fromJson(statusList); @@ -152,8 +143,7 @@ class ThreeTouchBloc extends Bloc { emit(UpdateState(threeTouchModel: deviceStatus)); } - void _changeFirstSwitch( - ChangeFirstSwitchStatusEvent event, Emitter emit) async { + void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(threeTouchModel: deviceStatus)); try { if (threeTouchGroup) { @@ -162,15 +152,11 @@ class ThreeTouchBloc extends Bloc { if (element.deviceId == event.deviceId) { element.firstSwitch = !event.value; } - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesValue = false; } }); - emit(UpdateGroupState( - threeTouchList: groupThreeTouchList, - allSwitches: allSwitchesValue)); + emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue)); } else { deviceStatus.firstSwitch = !event.value; emit(UpdateState(threeTouchModel: deviceStatus)); @@ -180,7 +166,7 @@ class ThreeTouchBloc extends Bloc { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: threeTouchGroup ? event.deviceId : threeTouchId, @@ -197,8 +183,8 @@ class ThreeTouchBloc extends Bloc { } } - void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, - Emitter emit) async { + void _changeSecondSwitch( + ChangeSecondSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(threeTouchModel: deviceStatus)); try { if (threeTouchGroup) { @@ -207,15 +193,11 @@ class ThreeTouchBloc extends Bloc { if (element.deviceId == event.deviceId) { element.secondSwitch = !event.value; } - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesValue = false; } }); - emit(UpdateGroupState( - threeTouchList: groupThreeTouchList, - allSwitches: allSwitchesValue)); + emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue)); } else { deviceStatus.secondSwitch = !event.value; emit(UpdateState(threeTouchModel: deviceStatus)); @@ -224,7 +206,7 @@ class ThreeTouchBloc extends Bloc { if (_timer != null) { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: threeTouchGroup ? event.deviceId : threeTouchId, @@ -241,8 +223,7 @@ class ThreeTouchBloc extends Bloc { } } - void _changeThirdSwitch( - ChangeThirdSwitchStatusEvent event, Emitter emit) async { + void _changeThirdSwitch(ChangeThirdSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(threeTouchModel: deviceStatus)); try { if (threeTouchGroup) { @@ -251,15 +232,11 @@ class ThreeTouchBloc extends Bloc { if (element.deviceId == event.deviceId) { element.thirdSwitch = !event.value; } - if (!element.firstSwitch || - !element.secondSwitch || - !element.thirdSwitch) { + if (!element.firstSwitch || !element.secondSwitch || !element.thirdSwitch) { allSwitchesValue = false; } }); - emit(UpdateGroupState( - threeTouchList: groupThreeTouchList, - allSwitches: allSwitchesValue)); + emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: allSwitchesValue)); } else { deviceStatus.thirdSwitch = !event.value; emit(UpdateState(threeTouchModel: deviceStatus)); @@ -269,7 +246,7 @@ class ThreeTouchBloc extends Bloc { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( DeviceControlModel( deviceId: threeTouchGroup ? event.deviceId : threeTouchId, @@ -298,21 +275,15 @@ class ThreeTouchBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeTouchId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch), threeTouchId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeTouchId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch), threeTouchId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeTouchId, - code: 'switch_3', - value: deviceStatus.thirdSwitch), + deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch), threeTouchId), ]); @@ -338,21 +309,15 @@ class ThreeTouchBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeTouchId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: threeTouchId, code: 'switch_1', value: deviceStatus.firstSwitch), threeTouchId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeTouchId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: threeTouchId, code: 'switch_2', value: deviceStatus.secondSwitch), threeTouchId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: threeTouchId, - code: 'switch_3', - value: deviceStatus.thirdSwitch), + deviceId: threeTouchId, code: 'switch_3', value: deviceStatus.thirdSwitch), threeTouchId), ]); @@ -374,10 +339,8 @@ class ThreeTouchBloc extends Bloc { groupThreeTouchList[i].secondSwitch = true; groupThreeTouchList[i].thirdSwitch = true; } - emit(UpdateGroupState( - threeTouchList: groupThreeTouchList, allSwitches: true)); - List allDeviceIds = - groupThreeTouchList.map((device) => device.deviceId).toList(); + emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: true)); + List allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', devicesUuid: allDeviceIds, @@ -406,8 +369,7 @@ class ThreeTouchBloc extends Bloc { } } - void _groupAllOff( - GroupAllOffEvent event, Emitter emit) async { + void _groupAllOff(GroupAllOffEvent event, Emitter emit) async { emit(LoadingNewSate(threeTouchModel: deviceStatus)); try { for (int i = 0; i < groupThreeTouchList.length; i++) { @@ -415,10 +377,8 @@ class ThreeTouchBloc extends Bloc { groupThreeTouchList[i].secondSwitch = false; groupThreeTouchList[i].thirdSwitch = false; } - List allDeviceIds = - groupThreeTouchList.map((device) => device.deviceId).toList(); - emit(UpdateGroupState( - threeTouchList: groupThreeTouchList, allSwitches: false)); + List allDeviceIds = groupThreeTouchList.map((device) => device.deviceId).toList(); + emit(UpdateGroupState(threeTouchList: groupThreeTouchList, allSwitches: false)); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', devicesUuid: allDeviceIds, @@ -447,20 +407,17 @@ class ThreeTouchBloc extends Bloc { } } - void _changeSliding( - ChangeSlidingSegment event, Emitter emit) async { + void _changeSliding(ChangeSlidingSegment event, Emitter emit) async { emit(ChangeSlidingSegmentState(value: event.value)); } - void _setCounterValue( - SetCounterValue event, Emitter emit) async { + void _setCounterValue(SetCounterValue event, Emitter emit) async { emit(LoadingNewSate(threeTouchModel: deviceStatus)); int seconds = 0; try { seconds = event.duration.inSeconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: threeTouchId, code: event.deviceCode, value: seconds), + DeviceControlModel(deviceId: threeTouchId, code: event.deviceCode, value: seconds), threeTouchId); if (response['success'] ?? false) { @@ -487,8 +444,7 @@ class ThreeTouchBloc extends Bloc { } } - void _getCounterValue( - GetCounterEvent event, Emitter emit) async { + void _getCounterValue(GetCounterEvent event, Emitter emit) async { emit(LoadingInitialState()); try { var response = await DevicesAPI.getDeviceStatus(threeTouchId); @@ -598,8 +554,7 @@ class ThreeTouchBloc extends Bloc { deviceId: threeTouchId, ); List jsonData = response; - listSchedule = - jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); + listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); emit(InitialState()); } on DioException catch (e) { final errorData = e.response!.data; @@ -610,13 +565,12 @@ class ThreeTouchBloc extends Bloc { int? getTimeStampWithoutSeconds(DateTime? dateTime) { if (dateTime == null) return null; - DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month, - dateTime.day, dateTime.hour, dateTime.minute); + DateTime dateTimeWithoutSeconds = + DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - Future toggleChange( - ToggleScheduleEvent event, Emitter emit) async { + Future toggleChange(ToggleScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.changeSchedule( @@ -635,8 +589,7 @@ class ThreeTouchBloc extends Bloc { } } - Future deleteSchedule( - DeleteScheduleEvent event, Emitter emit) async { + Future deleteSchedule(DeleteScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.deleteSchedule( @@ -656,15 +609,13 @@ class ThreeTouchBloc extends Bloc { } } - void toggleSelectedIndex( - ToggleSelectedEvent event, Emitter emit) { + void toggleSelectedIndex(ToggleSelectedEvent event, Emitter emit) { emit(LoadingInitialState()); selectedTabIndex = event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } - void toggleCreateSchedule( - ToggleCreateScheduleEvent event, Emitter emit) { + void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { emit(LoadingInitialState()); createSchedule = !createSchedule; selectedDays.clear(); @@ -682,8 +633,7 @@ class ThreeTouchBloc extends Bloc { String statusSelected = ''; String optionSelected = ''; - Future _changeStatus( - ChangeStatusEvent event, Emitter emit) async { + Future _changeStatus(ChangeStatusEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final Map> controlMap = { @@ -717,15 +667,11 @@ class ThreeTouchBloc extends Bloc { final selectedControl = controlMap[optionSelected]?[statusSelected]; if (selectedControl != null) { await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: threeTouchId, - code: optionSelected, - value: selectedControl), + DeviceControlModel(deviceId: threeTouchId, code: optionSelected, value: selectedControl), threeTouchId, ); } else { - emit(const FailedState( - error: 'Invalid statusSelected or optionSelected')); + emit(const FailedState(error: 'Invalid statusSelected or optionSelected')); } } on DioException catch (e) { final errorData = e.response!.data; diff --git a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart index 92163ae..7906348 100644 --- a/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart +++ b/lib/features/devices/bloc/two_gang_bloc/two_gang_bloc.dart @@ -35,8 +35,7 @@ class TwoGangBloc extends Bloc { bool createSchedule = false; List listSchedule = []; - TwoGangBloc({required this.twoGangId, required this.switchCode}) - : super(InitialState()) { + TwoGangBloc({required this.twoGangId, required this.switchCode}) : super(InitialState()) { on(_fetchTwoGangStatus); on(_twoGangUpdated); on(_changeFirstSwitch); @@ -66,15 +65,13 @@ class TwoGangBloc extends Bloc { int selectedTabIndex = 0; - void toggleSelectedIndex( - ToggleSelectedEvent event, Emitter emit) { + void toggleSelectedIndex(ToggleSelectedEvent event, Emitter emit) { emit(LoadingInitialState()); selectedTabIndex = event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } - void toggleCreateSchedule( - ToggleCreateScheduleEvent event, Emitter emit) { + void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { emit(LoadingInitialState()); createSchedule = !createSchedule; selectedDays.clear(); @@ -82,8 +79,7 @@ class TwoGangBloc extends Bloc { emit(UpdateCreateScheduleState(createSchedule)); } - void _fetchTwoGangStatus( - InitialEvent event, Emitter emit) async { + void _fetchTwoGangStatus(InitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { var response = await DevicesAPI.getDeviceStatus(twoGangId); @@ -102,21 +98,18 @@ class TwoGangBloc extends Bloc { _listenToChanges() { try { - DatabaseReference ref = - FirebaseDatabase.instance.ref('device-status/$twoGangId'); + DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoGangId'); Stream stream = ref.onValue; stream.listen((DatabaseEvent event) async { if (_timer != null) { await Future.delayed(const Duration(seconds: 2)); } - Map usersMap = - event.snapshot.value as Map; + Map usersMap = event.snapshot.value as Map; List statusList = []; usersMap['status'].forEach((element) { - statusList - .add(StatusModel(code: element['code'], value: element['value'])); + statusList.add(StatusModel(code: element['code'], value: element['value'])); }); deviceStatus = TwoGangModel.fromJson(statusList); @@ -131,8 +124,7 @@ class TwoGangBloc extends Bloc { emit(UpdateState(twoGangModel: deviceStatus)); } - void _changeFirstSwitch( - ChangeFirstSwitchStatusEvent event, Emitter emit) async { + void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { deviceStatus.firstSwitch = !event.value; @@ -141,10 +133,9 @@ class TwoGangBloc extends Bloc { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: twoGangId, code: 'switch_1', value: !event.value), + DeviceControlModel(deviceId: twoGangId, code: 'switch_1', value: !event.value), twoGangId); if (!response['success']) { @@ -156,8 +147,7 @@ class TwoGangBloc extends Bloc { } } - void _changeSecondSwitch( - ChangeSecondSwitchStatusEvent event, Emitter emit) async { + void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { deviceStatus.secondSwitch = !event.value; @@ -165,10 +155,9 @@ class TwoGangBloc extends Bloc { if (_timer != null) { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: twoGangId, code: 'switch_2', value: !event.value), + DeviceControlModel(deviceId: twoGangId, code: 'switch_2', value: !event.value), twoGangId); if (!response['success']) { @@ -191,15 +180,11 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch), twoGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch), twoGangId), ]); @@ -222,15 +207,11 @@ class TwoGangBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: twoGangId, code: 'switch_1', value: deviceStatus.firstSwitch), twoGangId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoGangId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: twoGangId, code: 'switch_2', value: deviceStatus.secondSwitch), twoGangId), ]); if (response.every((element) => !element['success'])) { @@ -251,8 +232,7 @@ class TwoGangBloc extends Bloc { groupTwoGangList[i].secondSwitch = true; } emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: true)); - List allDeviceIds = - groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -287,8 +267,7 @@ class TwoGangBloc extends Bloc { emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: false)); - List allDeviceIds = - groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -313,20 +292,17 @@ class TwoGangBloc extends Bloc { } } - void _changeSliding( - ChangeSlidingSegment event, Emitter emit) async { + void _changeSliding(ChangeSlidingSegment event, Emitter emit) async { emit(ChangeSlidingSegmentState(value: event.value)); } - void _setCounterValue( - SetCounterValue event, Emitter emit) async { + void _setCounterValue(SetCounterValue event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); int seconds = 0; try { seconds = event.duration.inSeconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: twoGangId, code: event.deviceCode, value: seconds), + DeviceControlModel(deviceId: twoGangId, code: event.deviceCode, value: seconds), twoGangId); if (response['success'] ?? false) { @@ -351,8 +327,7 @@ class TwoGangBloc extends Bloc { } } - void _getCounterValue( - GetCounterEvent event, Emitter emit) async { + void _getCounterValue(GetCounterEvent event, Emitter emit) async { emit(LoadingInitialState()); try { add(GetScheduleEvent()); @@ -460,8 +435,7 @@ class TwoGangBloc extends Bloc { deviceId: twoGangId, ); List jsonData = response; - listSchedule = - jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); + listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); emit(InitialState()); } on DioException catch (e) { final errorData = e.response!.data; @@ -472,13 +446,12 @@ class TwoGangBloc extends Bloc { int? getTimeStampWithoutSeconds(DateTime? dateTime) { if (dateTime == null) return null; - DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month, - dateTime.day, dateTime.hour, dateTime.minute); + DateTime dateTimeWithoutSeconds = + DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - Future toggleRepeat( - ToggleScheduleEvent event, Emitter emit) async { + Future toggleRepeat(ToggleScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.changeSchedule( @@ -497,8 +470,7 @@ class TwoGangBloc extends Bloc { } } - Future deleteSchedule( - DeleteScheduleEvent event, Emitter emit) async { + Future deleteSchedule(DeleteScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.deleteSchedule( @@ -518,8 +490,7 @@ class TwoGangBloc extends Bloc { } } - void _fetchTwoGangWizardStatus( - InitialWizardEvent event, Emitter emit) async { + void _fetchTwoGangWizardStatus(InitialWizardEvent event, Emitter emit) async { emit(LoadingInitialState()); try { devicesList = []; @@ -529,8 +500,7 @@ class TwoGangBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', '2G'); for (int i = 0; i < devicesList.length; i++) { - var response = - await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); + var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); List statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); @@ -553,16 +523,15 @@ class TwoGangBloc extends Bloc { return true; }); } - emit(UpdateGroupState( - twoGangList: groupTwoGangList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesOn)); } catch (e) { emit(FailedState(error: e.toString())); return; } } - void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event, - Emitter emit) async { + void _changeFirstWizardSwitch( + ChangeFirstWizardSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { bool allSwitchesValue = true; @@ -575,11 +544,9 @@ class TwoGangBloc extends Bloc { } }); - emit(UpdateGroupState( - twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); - List allDeviceIds = - groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); final response = await DevicesAPI.deviceBatchController( code: 'switch_1', devicesUuid: allDeviceIds, @@ -594,8 +561,8 @@ class TwoGangBloc extends Bloc { } } - void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event, - Emitter emit) async { + void _changeSecondWizardSwitch( + ChangeSecondWizardSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoGangModel: deviceStatus)); try { bool allSwitchesValue = true; @@ -607,11 +574,9 @@ class TwoGangBloc extends Bloc { allSwitchesValue = false; } }); - List allDeviceIds = - groupTwoGangList.map((device) => device.deviceId).toList(); + List allDeviceIds = groupTwoGangList.map((device) => device.deviceId).toList(); - emit(UpdateGroupState( - twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState(twoGangList: groupTwoGangList, allSwitches: allSwitchesValue)); final response = await DevicesAPI.deviceBatchController( code: 'switch_2', diff --git a/lib/features/devices/bloc/two_touch_bloc/two_touch_bloc.dart b/lib/features/devices/bloc/two_touch_bloc/two_touch_bloc.dart index 8391191..7f66724 100644 --- a/lib/features/devices/bloc/two_touch_bloc/two_touch_bloc.dart +++ b/lib/features/devices/bloc/two_touch_bloc/two_touch_bloc.dart @@ -40,8 +40,7 @@ class TwoTouchBloc extends Bloc { bool createSchedule = false; List listSchedule = []; - TwoTouchBloc({required this.twoTouchId, required this.switchCode}) - : super(InitialState()) { + TwoTouchBloc({required this.twoTouchId, required this.switchCode}) : super(InitialState()) { on(_fetchTwoTouchStatus); on(_twoTouchUpdated); on(_changeFirstSwitch); @@ -72,15 +71,13 @@ class TwoTouchBloc extends Bloc { int selectedTabIndex = 0; - void toggleSelectedIndex( - ToggleSelectedEvent event, Emitter emit) { + void toggleSelectedIndex(ToggleSelectedEvent event, Emitter emit) { emit(LoadingInitialState()); selectedTabIndex = event.index; emit(ChangeSlidingSegmentState(value: selectedTabIndex)); } - void toggleCreateSchedule( - ToggleCreateScheduleEvent event, Emitter emit) { + void toggleCreateSchedule(ToggleCreateScheduleEvent event, Emitter emit) { emit(LoadingInitialState()); createSchedule = !createSchedule; selectedDays.clear(); @@ -88,8 +85,7 @@ class TwoTouchBloc extends Bloc { emit(UpdateCreateScheduleState(createSchedule)); } - void _fetchTwoTouchStatus( - InitialEvent event, Emitter emit) async { + void _fetchTwoTouchStatus(InitialEvent event, Emitter emit) async { emit(LoadingInitialState()); try { var response = await DevicesAPI.getDeviceStatus(twoTouchId); @@ -108,21 +104,18 @@ class TwoTouchBloc extends Bloc { _listenToChanges() { try { - DatabaseReference ref = - FirebaseDatabase.instance.ref('device-status/$twoTouchId'); + DatabaseReference ref = FirebaseDatabase.instance.ref('device-status/$twoTouchId'); Stream stream = ref.onValue; stream.listen((DatabaseEvent event) async { if (_timer != null) { await Future.delayed(const Duration(seconds: 2)); } - Map usersMap = - event.snapshot.value as Map; + Map usersMap = event.snapshot.value as Map; List statusList = []; usersMap['status'].forEach((element) { - statusList - .add(StatusModel(code: element['code'], value: element['value'])); + statusList.add(StatusModel(code: element['code'], value: element['value'])); }); deviceStatus = TwoTouchModel.fromJson(statusList); @@ -137,8 +130,7 @@ class TwoTouchBloc extends Bloc { emit(UpdateState(twoTouchModel: deviceStatus)); } - void _changeFirstSwitch( - ChangeFirstSwitchStatusEvent event, Emitter emit) async { + void _changeFirstSwitch(ChangeFirstSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoTouchModel: deviceStatus)); try { deviceStatus.firstSwitch = !event.value; @@ -147,10 +139,9 @@ class TwoTouchBloc extends Bloc { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: twoTouchId, code: 'switch_1', value: !event.value), + DeviceControlModel(deviceId: twoTouchId, code: 'switch_1', value: !event.value), twoTouchId); if (!response['success']) { @@ -162,8 +153,7 @@ class TwoTouchBloc extends Bloc { } } - void _changeSecondSwitch( - ChangeSecondSwitchStatusEvent event, Emitter emit) async { + void _changeSecondSwitch(ChangeSecondSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoTouchModel: deviceStatus)); try { deviceStatus.secondSwitch = !event.value; @@ -171,10 +161,9 @@ class TwoTouchBloc extends Bloc { if (_timer != null) { _timer!.cancel(); } - _timer = Timer(const Duration(milliseconds: 500), () async { + _timer = Timer(const Duration(milliseconds: 100), () async { final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: twoTouchId, code: 'switch_2', value: !event.value), + DeviceControlModel(deviceId: twoTouchId, code: 'switch_2', value: !event.value), twoTouchId); if (!response['success']) { @@ -197,15 +186,11 @@ class TwoTouchBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoTouchId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: twoTouchId, code: 'switch_1', value: deviceStatus.firstSwitch), twoTouchId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoTouchId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: twoTouchId, code: 'switch_2', value: deviceStatus.secondSwitch), twoTouchId), ]); @@ -228,15 +213,11 @@ class TwoTouchBloc extends Bloc { final response = await Future.wait([ DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoTouchId, - code: 'switch_1', - value: deviceStatus.firstSwitch), + deviceId: twoTouchId, code: 'switch_1', value: deviceStatus.firstSwitch), twoTouchId), DevicesAPI.controlDevice( DeviceControlModel( - deviceId: twoTouchId, - code: 'switch_2', - value: deviceStatus.secondSwitch), + deviceId: twoTouchId, code: 'switch_2', value: deviceStatus.secondSwitch), twoTouchId), ]); if (response.every((element) => !element['success'])) { @@ -256,10 +237,8 @@ class TwoTouchBloc extends Bloc { groupTwoTouchList[i].firstSwitch = true; groupTwoTouchList[i].secondSwitch = true; } - emit( - UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: true)); - List allDeviceIds = - groupTwoTouchList.map((device) => device.deviceId).toList(); + emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: true)); + List allDeviceIds = groupTwoTouchList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -292,11 +271,9 @@ class TwoTouchBloc extends Bloc { groupTwoTouchList[i].secondSwitch = false; } - emit(UpdateGroupState( - twoTouchList: groupTwoTouchList, allSwitches: false)); + emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: false)); - List allDeviceIds = - groupTwoTouchList.map((device) => device.deviceId).toList(); + List allDeviceIds = groupTwoTouchList.map((device) => device.deviceId).toList(); final response1 = await DevicesAPI.deviceBatchController( code: 'switch_1', @@ -321,20 +298,17 @@ class TwoTouchBloc extends Bloc { } } - void _changeSliding( - ChangeSlidingSegment event, Emitter emit) async { + void _changeSliding(ChangeSlidingSegment event, Emitter emit) async { emit(ChangeSlidingSegmentState(value: event.value)); } - void _setCounterValue( - SetCounterValue event, Emitter emit) async { + void _setCounterValue(SetCounterValue event, Emitter emit) async { emit(LoadingNewSate(twoTouchModel: deviceStatus)); int seconds = 0; try { seconds = event.duration.inSeconds; final response = await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: twoTouchId, code: event.deviceCode, value: seconds), + DeviceControlModel(deviceId: twoTouchId, code: event.deviceCode, value: seconds), twoTouchId); if (response['success'] ?? false) { @@ -359,8 +333,7 @@ class TwoTouchBloc extends Bloc { } } - void _getCounterValue( - GetCounterEvent event, Emitter emit) async { + void _getCounterValue(GetCounterEvent event, Emitter emit) async { emit(LoadingInitialState()); try { add(GetScheduleEvent()); @@ -468,8 +441,7 @@ class TwoTouchBloc extends Bloc { deviceId: twoTouchId, ); List jsonData = response; - listSchedule = - jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); + listSchedule = jsonData.map((item) => ScheduleModel.fromJson(item)).toList(); emit(InitialState()); } on DioException catch (e) { final errorData = e.response!.data; @@ -480,13 +452,12 @@ class TwoTouchBloc extends Bloc { int? getTimeStampWithoutSeconds(DateTime? dateTime) { if (dateTime == null) return null; - DateTime dateTimeWithoutSeconds = DateTime(dateTime.year, dateTime.month, - dateTime.day, dateTime.hour, dateTime.minute); + DateTime dateTimeWithoutSeconds = + DateTime(dateTime.year, dateTime.month, dateTime.day, dateTime.hour, dateTime.minute); return dateTimeWithoutSeconds.millisecondsSinceEpoch ~/ 1000; } - Future toggleRepeat( - ToggleScheduleEvent event, Emitter emit) async { + Future toggleRepeat(ToggleScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.changeSchedule( @@ -505,8 +476,7 @@ class TwoTouchBloc extends Bloc { } } - Future deleteSchedule( - DeleteScheduleEvent event, Emitter emit) async { + Future deleteSchedule(DeleteScheduleEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final response = await DevicesAPI.deleteSchedule( @@ -526,8 +496,7 @@ class TwoTouchBloc extends Bloc { } } - void _fetchTwoTouchWizardStatus( - InitialWizardEvent event, Emitter emit) async { + void _fetchTwoTouchWizardStatus(InitialWizardEvent event, Emitter emit) async { emit(LoadingInitialState()); try { devicesList = []; @@ -537,8 +506,7 @@ class TwoTouchBloc extends Bloc { HomeCubit.getInstance().selectedSpace?.id ?? '', '2GT'); for (int i = 0; i < devicesList.length; i++) { - var response = - await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); + var response = await DevicesAPI.getDeviceStatus(devicesList[i].uuid ?? ''); List statusModelList = []; for (var status in response['status']) { statusModelList.add(StatusModel.fromJson(status)); @@ -561,16 +529,15 @@ class TwoTouchBloc extends Bloc { return true; }); } - emit(UpdateGroupState( - twoTouchList: groupTwoTouchList, allSwitches: allSwitchesOn)); + emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesOn)); } catch (e) { emit(FailedState(error: e.toString())); return; } } - void _changeFirstWizardSwitch(ChangeFirstWizardSwitchStatusEvent event, - Emitter emit) async { + void _changeFirstWizardSwitch( + ChangeFirstWizardSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoTouchModel: deviceStatus)); try { bool allSwitchesValue = true; @@ -583,8 +550,7 @@ class TwoTouchBloc extends Bloc { } }); - emit(UpdateGroupState( - twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue)); final response = await DevicesAPI.deviceBatchController( code: 'switch_1', devicesUuid: [event.deviceId], @@ -599,8 +565,8 @@ class TwoTouchBloc extends Bloc { } } - void _changeSecondWizardSwitch(ChangeSecondWizardSwitchStatusEvent event, - Emitter emit) async { + void _changeSecondWizardSwitch( + ChangeSecondWizardSwitchStatusEvent event, Emitter emit) async { emit(LoadingNewSate(twoTouchModel: deviceStatus)); try { bool allSwitchesValue = true; @@ -613,8 +579,7 @@ class TwoTouchBloc extends Bloc { } }); - emit(UpdateGroupState( - twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue)); + emit(UpdateGroupState(twoTouchList: groupTwoTouchList, allSwitches: allSwitchesValue)); final response = await DevicesAPI.deviceBatchController( code: 'switch_2', @@ -633,8 +598,7 @@ class TwoTouchBloc extends Bloc { String statusSelected = ''; String optionSelected = ''; - Future _changeStatus( - ChangeStatusEvent event, Emitter emit) async { + Future _changeStatus(ChangeStatusEvent event, Emitter emit) async { try { emit(LoadingInitialState()); final Map> controlMap = { @@ -663,14 +627,11 @@ class TwoTouchBloc extends Bloc { final selectedControl = controlMap[optionSelected]?[statusSelected]; if (selectedControl != null) { await DevicesAPI.controlDevice( - DeviceControlModel( - deviceId: twoTouchId, - code: optionSelected, - value: selectedControl), + DeviceControlModel(deviceId: twoTouchId, code: optionSelected, value: selectedControl), twoTouchId, ); } else { - emit( const FailedState(error: 'Invalid statusSelected or optionSelected')); + emit(const FailedState(error: 'Invalid statusSelected or optionSelected')); } } on DioException catch (e) { final errorData = e.response!.data; diff --git a/pubspec.yaml b/pubspec.yaml index 3d8626d..4dff6df 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: This is the mobile application project, developed with Flutter for # pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: "none" # Remove this line if you wish to publish to pub.dev -version: 1.0.5+30 +version: 1.0.5+31 environment: sdk: ">=3.0.6 <4.0.0"