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

170 lines
5.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
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';
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(
'保存'.tr,
style: TextStyle(
color: Colors.white,
fontSize: 24.sp,
fontWeight: FontWeight.w500,
),
),
),
],
),
body: EasyRefreshTool(
child: _buildBody(),
onRefresh: () {
logic.sendGetDeviceModelBleMessage();
},
),
);
}
Widget _buildBody() {
return Obx(
() => SingleChildScrollView(
child: Column(
children: [
// Container(
// width: 1.sw,
// decoration: BoxDecoration(color: Colors.white),
// child: Column(
// children: [
// RadioListTile(
// title: Text("男声".tr),
// value: 1,
// groupValue: state.selectedValue.value,
// onChanged: (value) {
// state.selectedValue.value = int.parse(value.toString());
// },
// ),
// RadioListTile(
// title: Text("女声".tr),
// value: 2,
// groupValue: state.selectedValue.value,
// onChanged: (value) {
// state.selectedValue.value = int.parse(value.toString());
// },
// )
// ],
// ),
// ),
SizedBox(
height: 8.h,
),
Column(
children: _buildList(),
),
],
),
),
);
}
List<Widget> _buildList() {
final languages = state.languages;
return List.generate(
languages.length,
(index) => _buildItem(languages[index], index),
);
}
_buildItem(PassthroughItem language, int index) {
final timbres = language.timbres;
final isSelected = state.selectPassthroughListIndex == index;
return ExpansionTile(
title: Text(
PassthroughLangHelper.getLangText(language.lang),
style: TextStyle(
fontSize: 24.sp,
fontWeight: isSelected ? FontWeight.bold : null,
),
),
onExpansionChanged: (bool expanded) {},
initiallyExpanded: false,
backgroundColor: Colors.white,
collapsedBackgroundColor: Colors.white,
expandedCrossAxisAlignment: CrossAxisAlignment.center,
expandedAlignment: Alignment.center,
shape: InputBorder.none,
maintainState: true,
// 去除展开状态下的边框
collapsedShape: InputBorder.none,
// 去除折叠状态下的边框
childrenPadding: EdgeInsets.only(left: 12.w),
children: List.generate(
timbres.length,
(int languageIndex) => ListTile(
title: Text(
timbres[languageIndex].name,
style: TextStyle(
fontSize: 22.sp,
fontWeight:
state.selectLanguageIndex == languageIndex && isSelected
? FontWeight.bold
: null,
),
),
trailing: state.selectLanguageIndex == languageIndex && isSelected
? Icon(
Icons.check_circle,
color: AppColors.mainColor,
) // 仅当选中时显示图标
: null, // 默认不显示
onTap: () {
// 更新选中的语音包
state.selectLanguageIndex.value = languageIndex;
// 更新选中的语言
state.selectPassthroughListIndex.value = index;
}, // 默认图标, // 右侧的图标
),
),
);
}
@override
void dispose() {
// TODO: implement dispose
super.dispose();
if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
}
}