|
|
|
@ -355,13 +355,34 @@ class TranslationView extends GetView<TranslationController> { |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
// 源文本 |
|
|
|
Text( |
|
|
|
item.sourceText, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16, |
|
|
|
color: Theme.of(context).textTheme.bodyLarge?.color, |
|
|
|
), |
|
|
|
// 源文本和删除按钮行 |
|
|
|
Row( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
// 源文本 |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
item.sourceText, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16, |
|
|
|
color: Theme.of(context).textTheme.bodyLarge?.color, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
// 删除按钮 - 只对完成态记录显示,与源文本平齐 |
|
|
|
if (!item.isIntermediate) |
|
|
|
GestureDetector( |
|
|
|
onTap: () => _showDeleteItemConfirmDialog(item), |
|
|
|
child: Container( |
|
|
|
padding: EdgeInsets.all(4.w), |
|
|
|
child: Icon( |
|
|
|
Icons.delete_outline, |
|
|
|
size: 18.sp, |
|
|
|
color: Colors.grey[500], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
if (item.translatedText.isNotEmpty) ...[ |
|
|
|
const SizedBox(height: 8), |
|
|
|
@ -380,20 +401,26 @@ class TranslationView extends GetView<TranslationController> { |
|
|
|
Row( |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
'${item.sourceLanguageName.tr} → ${item.targetLanguageName.tr}', |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 12, |
|
|
|
color: Theme.of(context).textTheme.bodySmall?.color, |
|
|
|
Expanded( |
|
|
|
child: Text( |
|
|
|
'${item.sourceLanguageName.tr} → ${item.targetLanguageName.tr}', |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 12, |
|
|
|
color: Theme.of(context).textTheme.bodySmall?.color, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
// 播放按钮 |
|
|
|
if (!item.isIntermediate) |
|
|
|
GestureDetector( |
|
|
|
onTap: () => controller.playTranslationItem(item), |
|
|
|
child: Icon( |
|
|
|
Icons.volume_up, |
|
|
|
size: 20, |
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
child: Container( |
|
|
|
padding: EdgeInsets.all(4.w), |
|
|
|
child: Icon( |
|
|
|
Icons.volume_up, |
|
|
|
size: 20.sp, |
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
@ -839,4 +866,136 @@ class TranslationView extends GetView<TranslationController> { |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 显示删除单条记录确认对话框 |
|
|
|
void _showDeleteItemConfirmDialog(TranslationItem item) { |
|
|
|
final isDarkMode = Theme.of(Get.context!).brightness == Brightness.dark; |
|
|
|
|
|
|
|
Get.dialog( |
|
|
|
AlertDialog( |
|
|
|
backgroundColor: isDarkMode ? AppColors.cardBackground : Colors.white, |
|
|
|
title: Text( |
|
|
|
'deleteTranslationRecord'.tr, // 删除翻译记录 |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 18.sp, |
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
color: isDarkMode ? Colors.white : Colors.black, |
|
|
|
), |
|
|
|
), |
|
|
|
content: Column( |
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
'deleteTranslationConfirm'.tr, // 确定要删除这条翻译记录吗?此操作无法撤销。 |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
color: isDarkMode ? Colors.grey[300] : Colors.black87, |
|
|
|
), |
|
|
|
), |
|
|
|
SizedBox(height: 12.h), |
|
|
|
// 显示要删除的记录预览 |
|
|
|
Container( |
|
|
|
padding: EdgeInsets.all(12.w), |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: isDarkMode |
|
|
|
? Colors.grey[800]?.withOpacity(0.5) |
|
|
|
: Colors.grey[100], |
|
|
|
borderRadius: BorderRadius.circular(8.r), |
|
|
|
border: Border.all( |
|
|
|
color: isDarkMode ? Colors.grey[700]! : Colors.grey[300]!, |
|
|
|
width: 1, |
|
|
|
), |
|
|
|
), |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
item.sourceText, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 14.sp, |
|
|
|
color: isDarkMode ? Colors.white : Colors.black, |
|
|
|
fontWeight: FontWeight.w500, |
|
|
|
), |
|
|
|
maxLines: 2, |
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
), |
|
|
|
if (item.translatedText.isNotEmpty) ...[ |
|
|
|
SizedBox(height: 4.h), |
|
|
|
Text( |
|
|
|
item.translatedText, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 14.sp, |
|
|
|
color: isDarkMode ? Colors.grey[300] : Colors.grey[700], |
|
|
|
), |
|
|
|
maxLines: 2, |
|
|
|
overflow: TextOverflow.ellipsis, |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
actions: [ |
|
|
|
TextButton( |
|
|
|
onPressed: () => Get.back(), |
|
|
|
child: Text( |
|
|
|
'cancel'.tr, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
color: isDarkMode ? Colors.grey[400] : Colors.grey[700], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
TextButton( |
|
|
|
onPressed: () { |
|
|
|
Get.back(); |
|
|
|
// 删除指定的翻译记录 |
|
|
|
_deleteTranslationItem(item); |
|
|
|
}, |
|
|
|
child: Text( |
|
|
|
'confirm'.tr, |
|
|
|
style: TextStyle( |
|
|
|
fontSize: 16.sp, |
|
|
|
color: Colors.red, |
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
shape: RoundedRectangleBorder( |
|
|
|
borderRadius: BorderRadius.circular(12.r), |
|
|
|
), |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// 删除翻译记录的具体实现 |
|
|
|
void _deleteTranslationItem(TranslationItem item) { |
|
|
|
try { |
|
|
|
// 调用控制器的删除方法 |
|
|
|
controller.deleteTranslationItem(item.sessionId, item.timestamp); |
|
|
|
|
|
|
|
// 显示删除成功提示 |
|
|
|
Get.snackbar( |
|
|
|
'删除成功', // deleteSuccess |
|
|
|
'已删除该翻译记录', // deleteTranslationSuccess |
|
|
|
snackPosition: SnackPosition.BOTTOM, |
|
|
|
backgroundColor: Get.isDarkMode ? Colors.grey[800] : Colors.grey[200], |
|
|
|
colorText: Get.isDarkMode ? Colors.white : Colors.black, |
|
|
|
duration: const Duration(seconds: 2), |
|
|
|
); |
|
|
|
} catch (e) { |
|
|
|
// 显示删除失败提示 |
|
|
|
Get.snackbar( |
|
|
|
'删除失败', // deleteFailed |
|
|
|
'删除翻译记录时发生错误: ${e.toString()}', // deleteTranslationError |
|
|
|
snackPosition: SnackPosition.BOTTOM, |
|
|
|
backgroundColor: Colors.red[400], |
|
|
|
colorText: Colors.white, |
|
|
|
duration: const Duration(seconds: 3), |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|