diff --git a/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_logic.dart b/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_logic.dart index 953fb79f..8e22bbb8 100644 --- a/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_logic.dart +++ b/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_logic.dart @@ -439,9 +439,24 @@ class SpeechLanguageSettingsLogic extends BaseGetXController { _handlerVoicePackageConfigureConfirmation( VoicePackageConfigureConfirmationReply reply, ) async { - final int status = reply.data[2]; - switch (status) { - case 0x00: + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + }); + final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre( + data: { + 'lang': state.tempLangStr.value, + 'timbre': state.tempTimbreStr.value, + }, + lockId: state.lockSetInfoData.value.lockId!, + ); + if (entity.errorCode!.codeIsSuccessful) { + showSuccess('设置成功'.tr, something: () async { + state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = + state.tempLangStr.value; + state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre + ?.timbre = state.tempTimbreStr.value; + await BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { @@ -458,10 +473,8 @@ class SpeechLanguageSettingsLogic extends BaseGetXController { showBlueConnetctToast(); } }); - break; - default: - showToast('设置'.tr + '失败'.tr); - break; + await Future.delayed(Duration(seconds: 1)); + }); } } @@ -470,24 +483,6 @@ class SpeechLanguageSettingsLogic extends BaseGetXController { switch (status) { case 0x00: cancelBlueConnetctToastTimer(); - final LoginEntity entity = - await ApiRepository.to.settingCurrentVoiceTimbre( - data: { - 'lang': state.tempLangStr.value, - 'timbre': state.tempTimbreStr.value, - }, - lockId: state.lockSetInfoData.value.lockId!, - ); - if (entity.errorCode!.codeIsSuccessful) { - showSuccess('设置成功'.tr, something: () { - state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre - ?.lang = state.tempLangStr.value; - state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre - ?.timbre = state.tempTimbreStr.value; - eventBus.fire( - PassCurrentLockInformationEvent(state.lockSetInfoData.value)); - }); - } dismissEasyLoading(); break; default: @@ -522,7 +517,6 @@ class SpeechLanguageSettingsLogic extends BaseGetXController { languageCode = languageCode.replaceAll('\u0000', ''); // 移除空字符 (null bytes) - if (languageCode != null && languageCode != '') { final indexWhere = state.languages .indexWhere((element) => element.lang == languageCode); diff --git a/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_page.dart b/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_page.dart index 59b45004..d082456d 100644 --- a/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_page.dart +++ b/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_page.dart @@ -64,7 +64,7 @@ class _SpeechLanguageSettingsPageState return CommonItem( leftTitel: soundType, leftTitleStyle: TextStyle( - fontSize: 22.sp, + fontSize: 20.sp, fontWeight: state.selectSoundTypeIndex.value == index ? FontWeight.bold : null, @@ -111,7 +111,7 @@ class _SpeechLanguageSettingsPageState return CommonItem( leftTitel: item.langText, leftTitleStyle: TextStyle( - fontSize: 22.sp, + fontSize: 20.sp, fontWeight: state.selectPassthroughListIndex.value == index ? FontWeight.bold : null, diff --git a/lib/mine/addLock/lock_voice_setting/lock_voice_setting_logic.dart b/lib/mine/addLock/lock_voice_setting/lock_voice_setting_logic.dart index 1fc00183..221c9d6f 100644 --- a/lib/mine/addLock/lock_voice_setting/lock_voice_setting_logic.dart +++ b/lib/mine/addLock/lock_voice_setting/lock_voice_setting_logic.dart @@ -84,22 +84,42 @@ class LockVoiceSettingLogic extends BaseGetXController { showBlueConnetctToastTimer(action: () { dismissEasyLoading(); }); - await BlueManage().blueSendData(BlueManage().connectDeviceName, - (BluetoothConnectionState deviceConnectionState) async { - if (deviceConnectionState == BluetoothConnectionState.connected) { - await BlueManage().writeCharacteristicWithResponse( - SetVoicePackageFinalResult( - lockID: BlueManage().connectDeviceName, - languageCode: state.tempLangStr.value, - ).packageData(), - ); - } else if (deviceConnectionState == - BluetoothConnectionState.disconnected) { - dismissEasyLoading(); - cancelBlueConnetctToastTimer(); - showBlueConnetctToast(); - } - }); + final LoginEntity entity = await ApiRepository.to.settingCurrentVoiceTimbre( + data: { + 'lang': state.tempLangStr.value, + 'timbre': state.tempTimbreStr.value, + }, + lockId: state.lockSetInfoData.value.lockId!, + ); + if (entity.errorCode!.codeIsSuccessful) { + showSuccess('设置成功'.tr, something: () async { + state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang = + state.tempLangStr.value; + state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre + ?.timbre = state.tempTimbreStr.value; + + await BlueManage().blueSendData(BlueManage().connectDeviceName, + (BluetoothConnectionState deviceConnectionState) async { + if (deviceConnectionState == BluetoothConnectionState.connected) { + await BlueManage().writeCharacteristicWithResponse( + SetVoicePackageFinalResult( + lockID: BlueManage().connectDeviceName, + languageCode: state.tempLangStr.value, + ).packageData(), + ); + } else if (deviceConnectionState == + BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + showBlueConnetctToast(); + } + }); + await Future.delayed(Duration(seconds: 1)); + eventBus + .fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + Get.offAllNamed(Routers.starLockMain); + }); + } } void handleSetResult(SetVoicePackageFinalResultReply reply) async { @@ -107,26 +127,6 @@ class LockVoiceSettingLogic extends BaseGetXController { switch (status) { case 0x00: cancelBlueConnetctToastTimer(); - final LoginEntity entity = - await ApiRepository.to.settingCurrentVoiceTimbre( - data: { - 'lang': state.tempLangStr.value, - 'timbre': state.tempTimbreStr.value, - }, - lockId: state.lockSetInfoData.value.lockId!, - ); - if (entity.errorCode!.codeIsSuccessful) { - showSuccess('设置成功'.tr, something: () { - state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre - ?.lang = state.tempLangStr.value; - state.lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre - ?.timbre = state.tempTimbreStr.value; - - eventBus.fire( - PassCurrentLockInformationEvent(state.lockSetInfoData.value)); - Get.offAllNamed(Routers.starLockMain); - }); - } dismissEasyLoading(); break; default: @@ -473,33 +473,25 @@ class LockVoiceSettingLogic extends BaseGetXController { //成功 cancelBlueConnetctToastTimer(); -// 1. 计算 LanguageCode 在字节数组中的起始和结束索引 -// CmdID (2 bytes) + Status (1 byte) = 3 bytes -> LanguageCode 从索引 3 开始 const int languageCodeStartIndex = 3; const int languageCodeLength = 20; const int languageCodeEndIndex = languageCodeStartIndex + languageCodeLength; // 23 -// 2. 检查数据长度是否足够 if (reply.data.length < languageCodeEndIndex) { throw Exception( 'Reply data is too short to contain LanguageCode. Expected at least $languageCodeEndIndex bytes, got ${reply.data.length}'); } -// 3. 从字节数组中截取 LanguageCode 对应的字节段 + List languageCodeBytes = reply.data.sublist(languageCodeStartIndex, languageCodeEndIndex); -// 4. 将字节列表转换为字符串 -// 通常这种编码是 UTF-8 或 ASCII String languageCode = String.fromCharCodes(languageCodeBytes); -// 5. (可选) 清理字符串:移除可能的填充字符(如空字符 '\0' 或空格) -// 因为字段长度固定为20,不足的部分可能用 '\0' 填充 languageCode = languageCode.trim(); // 移除首尾空格 languageCode = languageCode.replaceAll('\u0000', ''); // 移除空字符 (null bytes) -// 6. 使用提取到的 languageCode print('LanguageCode: $languageCode'); // 例如: zh_CN, en_US if (languageCode != null && languageCode != '') { diff --git a/lib/mine/addLock/lock_voice_setting/lock_voice_setting_page.dart b/lib/mine/addLock/lock_voice_setting/lock_voice_setting_page.dart index 84502622..74b992b9 100644 --- a/lib/mine/addLock/lock_voice_setting/lock_voice_setting_page.dart +++ b/lib/mine/addLock/lock_voice_setting/lock_voice_setting_page.dart @@ -96,7 +96,7 @@ class _LockVoiceSettingState extends State { return CommonItem( leftTitel: soundType, leftTitleStyle: TextStyle( - fontSize: 22.sp, + fontSize: 20.sp, fontWeight: state.selectSoundTypeIndex.value == index ? FontWeight.bold : null, @@ -142,7 +142,7 @@ class _LockVoiceSettingState extends State { return CommonItem( leftTitel: item.langText, leftTitleStyle: TextStyle( - fontSize: 22.sp, + fontSize: 20.sp, fontWeight: state.selectPassthroughListIndex.value == index ? FontWeight.bold @@ -152,7 +152,7 @@ class _LockVoiceSettingState extends State { isHaveLine: true, isHaveDirection: false, isHaveRightWidget: true, - leftTitleMaxWidth: 0.9.sw, + leftTitleMaxWidth: 0.85.sw, rightWidget: state.selectPassthroughListIndex.value == index ? Image(