Browse Source

style(translation): 修正注释错别字并优化代码格式

- 将“需要是开启”改为“需要时开启”
- 移除多余空行
- 统一代码缩进和换行格式
weicu
lxm 1 year ago
parent
commit
cd1fbf486f
  1. 2
      lib/modules/translation/views/translation_detail_view.dart
  2. 271
      lib/modules/translation/views/translation_view.dart

2
lib/modules/translation/views/translation_detail_view.dart

@ -110,7 +110,7 @@ class TranslationDetailView extends GetView<TranslationDetailController> {
isDarkMode: isDarkMode, isDarkMode: isDarkMode,
)), )),
), ),
//屏蔽“记录摘要”,需要是开启 //屏蔽“记录摘要”,需要时开启
// SizedBox(width: 12.w), // SizedBox(width: 12.w),
// Expanded( // Expanded(
// child: Obx(() => _buildTabButton( // child: Obx(() => _buildTabButton(

271
lib/modules/translation/views/translation_view.dart

@ -109,7 +109,6 @@ class TranslationView extends GetView<TranslationController> {
)), )),
centerTitle: true, centerTitle: true,
actions: [ actions: [
Obx(() { Obx(() {
if (controller.isRecording.value) { if (controller.isRecording.value) {
// 录音中:显示红色计时器样式,点击可停止录音 // 录音中:显示红色计时器样式,点击可停止录音
@ -305,7 +304,8 @@ class TranslationView extends GetView<TranslationController> {
itemCount: itemCount, itemCount: itemCount,
itemBuilder: (context, index) { itemBuilder: (context, index) {
// 如果是最后一项且有更多历史记录,显示加载指示器(reverse模式下) // 如果是最后一项且有更多历史记录,显示加载指示器(reverse模式下)
if (index == controller.translationHistory.length && controller.hasMoreHistory.value) { if (index == controller.translationHistory.length &&
controller.hasMoreHistory.value) {
return _buildLoadMoreIndicator(); return _buildLoadMoreIndicator();
} }
@ -313,7 +313,8 @@ class TranslationView extends GetView<TranslationController> {
final historyIndex = controller.translationHistory.length - 1 - index; final historyIndex = controller.translationHistory.length - 1 - index;
// 检查索引是否有效(reverse模式下的索引验证) // 检查索引是否有效(reverse模式下的索引验证)
if (historyIndex < 0 || historyIndex >= controller.translationHistory.length) { if (historyIndex < 0 ||
historyIndex >= controller.translationHistory.length) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
@ -668,148 +669,153 @@ class TranslationView extends GetView<TranslationController> {
// 显示语言选择对话框 // 显示语言选择对话框
void _showLanguageSelectionDialog(bool isSource, bool isDarkMode) { void _showLanguageSelectionDialog(bool isSource, bool isDarkMode) {
Get.dialog( Get.dialog(
Dialog( Dialog(
backgroundColor: isDarkMode ? Colors.grey[900] : Colors.white, backgroundColor: isDarkMode ? Colors.grey[900] : Colors.white,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16.r), // 统一圆角尺寸为16 borderRadius: BorderRadius.circular(16.r), // 统一圆角尺寸为16
), ),
insetPadding: EdgeInsets.symmetric(horizontal: 20.w), insetPadding: EdgeInsets.symmetric(horizontal: 20.w),
child: Padding( // 使用Padding替代Container的padding child: Padding(
padding: EdgeInsets.all(12.w), // 统一内边距 // 使用Padding替代Container的padding
child: Column( padding: EdgeInsets.all(12.w), // 统一内边距
mainAxisSize: MainAxisSize.min, child: Column(
crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min,
children: [ crossAxisAlignment: CrossAxisAlignment.start,
// 标题区域 children: [
Padding( // 标题区域
padding: EdgeInsets.symmetric(horizontal: 8.w), Padding(
child: Text( padding: EdgeInsets.symmetric(horizontal: 8.w),
isSource child: Text(
? 'selectSourceLanguage'.tr isSource
: 'selectTargetLanguage'.tr, // 保留源语言/目标语言区分 ? 'selectSourceLanguage'.tr
style: TextStyle( : 'selectTargetLanguage'.tr, // 保留源语言/目标语言区分
fontSize: 18.sp, // 调整字号 style: TextStyle(
fontWeight: FontWeight.w600, // 使用数字字重 fontSize: 18.sp, // 调整字号
color: isDarkMode ? Colors.white : Colors.black87, // 优化文本颜色 fontWeight: FontWeight.w600, // 使用数字字重
color: isDarkMode ? Colors.white : Colors.black87, // 优化文本颜色
),
), ),
), ),
), SizedBox(height: 16.h),
SizedBox(height: 16.h),
// 语言列表区域
// 语言列表区域 Container(
Container( constraints: BoxConstraints(maxHeight: 0.5.sh),
constraints: BoxConstraints(maxHeight: 0.5.sh), child: SingleChildScrollView(
child: SingleChildScrollView( child: Column(
child: Column( mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children:
children: controller.supportedLanguages.keys.map((language) { controller.supportedLanguages.keys.map((language) {
return Obx(() { return Obx(() {
final currentLanguage = isSource final currentLanguage = isSource
? controller.sourceLanguage.value ? controller.sourceLanguage.value
: controller.targetLanguage.value; : controller.targetLanguage.value;
final isSelected = currentLanguage == language; final isSelected = currentLanguage == language;
return GestureDetector( // 改用手势检测器实现点击 return GestureDetector(
onTap: () { // 改用手势检测器实现点击
if (isSource) { onTap: () {
controller.setSourceLanguage(language); if (isSource) {
} else { controller.setSourceLanguage(language);
controller.setTargetLanguage(language); } else {
} controller.setTargetLanguage(language);
Get.back(); }
}, Get.back();
child: Container( },
margin: EdgeInsets.only(bottom: 10.h), // 添加项间距 child: Container(
padding: EdgeInsets.all(10.w), // 统一内边距 margin: EdgeInsets.only(bottom: 10.h), // 添加项间距
decoration: BoxDecoration( padding: EdgeInsets.all(10.w), // 统一内边距
color: isSelected // 选中状态背景色 decoration: BoxDecoration(
? (isDarkMode color: isSelected // 选中状态背景色
? const Color(0xFF6200EE).withOpacity(0.2) ? (isDarkMode
: Colors.blue.withOpacity(0.1)) ? const Color(0xFF6200EE).withOpacity(0.2)
: (isDarkMode // 未选中状态背景色 : Colors.blue.withOpacity(0.1))
? Colors.white.withOpacity(0.05) : (isDarkMode // 未选中状态背景色
: Colors.grey[200]!), ? Colors.white.withOpacity(0.05)
borderRadius: BorderRadius.circular(12.r), // 项圆角 : Colors.grey[200]!),
border: Border.all( // 选中状态边框 borderRadius: BorderRadius.circular(12.r), // 项圆角
color: isSelected border: Border.all(
? (isDarkMode // 选中状态边框
? const Color(0xFF6200EE) color: isSelected
: Colors.blue) ? (isDarkMode
: (isDarkMode // 未选中状态背景色 ? const Color(0xFF6200EE)
? Colors.white.withOpacity(0.05) : Colors.blue)
: Colors.grey[200]!), : (isDarkMode // 未选中状态背景色
width: 1, ? Colors.white.withOpacity(0.05)
: Colors.grey[200]!),
width: 1,
),
), ),
), child: Row(
child: Row( children: [
children: [ // 语言名称
// 语言名称 Expanded(
Expanded( child: Text(
child: Text( language.tr,
language.tr, style: TextStyle(
style: TextStyle( fontSize: 16.sp,
fontSize: 16.sp, fontWeight: FontWeight.w500,
fontWeight: FontWeight.w500, color: isDarkMode
color: isDarkMode ? Colors.white
? Colors.white : Colors.black87,
: Colors.black87, overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis, ),
), ),
), ),
), // 选中指示器
// 选中指示器 Container(
Container( width: 24.w,
width: 24.w, height: 24.w,
height: 24.w, decoration: BoxDecoration(
decoration: BoxDecoration( color: isSelected // 动态颜色
color: isSelected // 动态颜色 ? (isDarkMode
? (isDarkMode ? const Color(0xFF6200EE)
? const Color(0xFF6200EE) : Colors.blue)
: Colors.blue) : (isDarkMode
: (isDarkMode ? Colors.white.withOpacity(0.1)
? Colors.white.withOpacity(0.1) : Colors.grey[300]),
: Colors.grey[300]), shape: BoxShape.circle, // 圆形样式
shape: BoxShape.circle, // 圆形样式 ),
child: isSelected
? Icon(
// 选中时显示对勾
Icons.check,
size: 16.w,
color: Colors.white,
)
: null,
), ),
child: isSelected ],
? Icon( // 选中时显示对勾 ),
Icons.check,
size: 16.w,
color: Colors.white,
)
: null,
),
],
), ),
), );
); });
}); }).toList(),
}).toList(), ),
), ),
), ),
), SizedBox(height: 16.h),
SizedBox(height: 16.h),
// 取消按钮
// 取消按钮 Align(
Align( alignment: Alignment.centerRight,
alignment: Alignment.centerRight, child: TextButton(
child: TextButton( onPressed: () => Get.back(),
onPressed: () => Get.back(), child: Text(
child: Text( 'cancel'.tr,
'cancel'.tr, style: TextStyle(
style: TextStyle( color: isDarkMode ? const Color(0xFF6200EE) : Colors.blue,
color: isDarkMode ? const Color(0xFF6200EE) : Colors.blue, ),
), ),
), ),
), ),
), ],
], ),
), ),
), ),
), );
); }
}
// 构建加载更多指示器 // 构建加载更多指示器
Widget _buildLoadMoreIndicator() { Widget _buildLoadMoreIndicator() {
@ -853,7 +859,8 @@ class TranslationView extends GetView<TranslationController> {
child: GestureDetector( child: GestureDetector(
onTap: () => controller.loadMoreHistory(), onTap: () => controller.loadMoreHistory(),
child: Container( child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), padding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.red[50], color: Colors.red[50],
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),

Loading…
Cancel
Save