app-starlock/lib/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_page.dart

163 lines
5.5 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
2025-07-17 14:56:56 +08:00
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/main/lockDetail/lockDetail/passthrough_item.dart';
import 'package:star_lock/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_logic.dart';
import 'package:star_lock/main/lockDetail/lockSet/speechLanguageSettings/speech_language_settings_state.dart';
import 'package:star_lock/tools/EasyRefreshTool.dart';
2025-07-25 14:59:54 +08:00
import 'package:star_lock/tools/commonItem.dart';
import 'package:star_lock/tools/titleAppBar.dart';
class SpeechLanguageSettingsPage extends StatefulWidget {
const SpeechLanguageSettingsPage();
@override
State<SpeechLanguageSettingsPage> createState() =>
_SpeechLanguageSettingsPageState();
}
class _SpeechLanguageSettingsPageState
extends State<SpeechLanguageSettingsPage> {
final SpeechLanguageSettingsLogic logic =
Get.put(SpeechLanguageSettingsLogic());
final SpeechLanguageSettingsState state =
Get.find<SpeechLanguageSettingsLogic>().state;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: '锁语音包设置'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor,
actionsList: [
TextButton(
onPressed: logic.saveSpeechLanguageSettings,
child: Text(
2025-07-26 16:11:58 +08:00
'下载'.tr,
style: TextStyle(
color: Colors.white,
fontSize: 24.sp,
fontWeight: FontWeight.w500,
),
),
),
],
),
2025-07-25 14:59:54 +08:00
body: _buildBody(),
);
}
Widget _buildBody() {
return Obx(
2025-07-17 14:56:56 +08:00
() => SingleChildScrollView(
child: Column(
children: [
2025-07-25 14:59:54 +08:00
Container(
width: 1.sw,
decoration: BoxDecoration(color: Colors.white),
child: ListView.builder(
itemCount: state.soundTypeList.length,
itemBuilder: (BuildContext context, int index) {
// 判断是否是最后一个元素(索引等于 itemCount - 1
final isLastItem = index == state.soundTypeList.length - 1;
// 获取当前平台数据(假设 platFormSet 是 RxList<Platform>
final platform = state.soundTypeList.value[index];
return CommonItem(
leftTitel: state.soundTypeList.value[index],
rightTitle: '',
isHaveLine: !isLastItem,
// 最后一个元素不显示分割线(取反)
isHaveDirection: false,
isHaveRightWidget: true,
rightWidget: Radio<String>(
// Radio 的值:使用平台的唯一标识(如 id
value: platform,
// 当前选中的值:与 selectPlatFormIndex 关联的 id
groupValue: state.soundTypeList
.value[state.selectSoundTypeIndex.value],
// 选中颜色(可选,默认主题色)
activeColor: AppColors.mainColor,
// 点击 Radio 时回调(更新选中索引)
onChanged: (value) {
if (value != null) {
setState(() {
// 找到当前选中平台的索引(根据 id 匹配)
final newIndex = state.soundTypeList.value
.indexWhere((p) => p == value);
if (newIndex != -1) {
state.selectSoundTypeIndex.value = newIndex;
}
});
}
},
),
action: () {
setState(() {
state.selectSoundTypeIndex.value = index;
});
},
);
},
shrinkWrap: true,
physics: const AlwaysScrollableScrollPhysics(),
),
),
SizedBox(
height: 8.h,
),
Column(
children: _buildList(),
),
],
2025-07-17 14:56:56 +08:00
),
),
);
}
List<Widget> _buildList() {
2025-07-26 16:11:58 +08:00
final appLocalLanguages = state.languages;
return List.generate(
2025-07-25 14:59:54 +08:00
appLocalLanguages.length,
(index) => _buildItem(
appLocalLanguages[index],
index,
),
);
}
2025-07-17 14:56:56 +08:00
@override
void dispose() {
super.dispose();
if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
}
2025-07-25 14:59:54 +08:00
2025-07-26 16:11:58 +08:00
_buildItem(PassthroughItem item, index) {
2025-07-25 14:59:54 +08:00
return CommonItem(
2025-07-26 16:11:58 +08:00
leftTitel: item.langText,
2025-07-25 14:59:54 +08:00
rightTitle: '',
isHaveLine: true,
isHaveDirection: false,
isHaveRightWidget: true,
rightWidget: state.selectPassthroughListIndex.value == index
? Image(
image: const AssetImage('images/icon_item_checked.png'),
width: 30.w,
height: 30.w,
fit: BoxFit.contain,
)
: Container(),
action: () {
state.selectPassthroughListIndex.value = index;
},
);
}
}