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

161 lines
5.7 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/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(
'下载'.tr,
style: TextStyle(
color: Colors.white,
fontSize: 24.sp,
fontWeight: FontWeight.w500,
),
),
),
],
),
body: Obx(
() => ListView(
padding: EdgeInsets.zero,
children: [
// 语音类型选择区
Container(
color: Colors.white,
child: Column(
children: List.generate(
state.soundTypeList.length,
(index) {
final isLastItem = index == state.soundTypeList.length - 1;
final soundType = state.soundTypeList.value[index];
return CommonItem(
leftTitel: soundType,
leftTitleStyle: TextStyle(
fontSize: 22.sp,
fontWeight: state.selectSoundTypeIndex.value == index
? FontWeight.bold
: null,
),
rightTitle: '',
isHaveLine: !isLastItem,
isHaveDirection: false,
isHaveRightWidget: true,
rightWidget: Radio<String>(
value: soundType,
groupValue: state.soundTypeList
.value[state.selectSoundTypeIndex.value],
activeColor: AppColors.mainColor,
onChanged: (value) {
if (value != null) {
final newIndex = state.soundTypeList.value
.indexWhere((p) => p == value);
if (newIndex != -1) {
state.selectSoundTypeIndex.value = newIndex;
}
}
},
),
action: () {
state.selectSoundTypeIndex.value = index;
},
);
},
),
),
),
SizedBox(
height: 8.h,
),
// 语言包列表区
Obx(
() => Container(
color: Colors.transparent,
child: Column(
children: List.generate(
state.languages.length,
(index) {
final item = state.languages[index];
return CommonItem(
leftTitel: item.langText,
leftTitleStyle: TextStyle(
fontSize: 22.sp,
fontWeight: state.selectPassthroughListIndex.value == index
? FontWeight.bold
: null,
),
rightTitle: '',
isHaveLine: true,
isHaveDirection: false,
isHaveRightWidget: true,
leftTitleMaxWidth: 0.9.sw,
// 设置左侧标题最大宽度
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;
},
);
},
),
),
),
),
],
),
),
);
}
@override
void dispose() {
super.dispose();
if (EasyLoading.isShow) {
EasyLoading.dismiss(animation: true);
}
}
}