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 781df709..8a75a1bd 100644 --- a/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_logic.dart +++ b/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_logic.dart @@ -45,10 +45,9 @@ class SpeechLanguageSettingsLogic extends BaseGetXController { } else if (reply is VoicePackageConfigureProcessReply) { _handlerVoicePackageConfigureProcess(reply); } else if (reply is VoicePackageConfigureConfirmationReply) { - _handlerVoicePackageConfigureConfirmation(reply); + handleVoiceConfigureThrottled(reply); } }); - await initList(); } @@ -110,14 +109,22 @@ class SpeechLanguageSettingsLogic extends BaseGetXController { .lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.lang; final timbre = state .lockSetInfoData.value.lockSettingInfo?.currentVoiceTimbre?.timbre; - state.languages.value.forEach((element) { - final timbres = element.timbres; - timbres.forEach((item) { - if (lang == element.lang && item.timbre == timbre) { - state.selectSoundTypeIndex.value = item.isFemale; + // 传统 for 循环,直接通过索引访问 + for (int i = 0; i < state.languages.length; i++) { + final language = state.languages[i]; // 当前元素 + if (language.lang == lang) { + print('匹配到下标:$i,元素:$language'); + final timbres = language.timbres; + for (int j = 0; j < timbres.length; j++) { + final item = timbres[j]; + if (lang == language.lang && item.timbre == timbre) { + state.selectSoundTypeIndex.value = item.isFemale; + state.selectPassthroughListIndex.value = i; + break; + } } - }); - }); + } + } } } catch (e) { debugPrint('获取语音包出现错误:$e'); @@ -358,7 +365,31 @@ class SpeechLanguageSettingsLogic extends BaseGetXController { super.onClose(); } - void _handlerVoicePackageConfigureConfirmation( + bool _isThrottled = false; + + void handleVoiceConfigureThrottled( + VoicePackageConfigureConfirmationReply reply, + ) { + if (_isThrottled) return; + + _isThrottled = true; + + // 执行你的逻辑 + _executeLogic(reply); + + // 设置节流时间(比如 1 秒) + Future.delayed(Duration(seconds: 1), () { + _isThrottled = false; + }); + } + + Future _executeLogic( + VoicePackageConfigureConfirmationReply reply) async { + await _handlerVoicePackageConfigureConfirmation(reply); + dismissEasyLoading(); + } + + _handlerVoicePackageConfigureConfirmation( VoicePackageConfigureConfirmationReply reply, ) async { final int status = reply.data[2];