Browse Source

feat(theme): 实现主题模式系统跟随功能并增强暗黑模式支持

refactor: 重构主题服务以支持系统/浅色/深色三种模式
style: 为图片翻译模块添加暗黑模式样式支持
chore: 在日志信息中添加开发者前缀
weicu
lxm 12 months ago
parent
commit
45bac7d908
  1. 64
      lib/core/themes/theme_service.dart
  2. 6
      lib/data/services/version_update_service.dart
  3. 2
      lib/modules/login/controllers/login_controller.dart
  4. 74
      lib/modules/picture_translation/views/picture_translation_history_detail_view.dart
  5. 267
      lib/modules/picture_translation/views/picture_translation_view.dart

64
lib/core/themes/theme_service.dart

@ -5,34 +5,80 @@ import '../../core/utils/logger.dart';
class ThemeService {
final _box = GetStorage();
// 旧版布尔键,兼容历史数据
final _key = 'isDarkMode';
// 新版字符串键,支持系统跟随/深色/浅色
final _modeKey = 'themeModePreference';
/// 获取主题模式
/// 获取主题模式(优先读取新版字符串偏好;否则回退到旧版布尔值;都没有则跟随系统)
ThemeMode getThemeMode() {
final isDarkMode = isSavedDarkMode();
Logger.info('获取保存的主题: ${isDarkMode ? "暗黑" : "浅色"}');
return isDarkMode ? ThemeMode.dark : ThemeMode.light;
try {
final String? pref = _box.read<String>(_modeKey);
if (pref != null) {
switch (pref) {
case 'system':
Logger.info('获取保存的主题: 系统跟随');
return ThemeMode.system;
case 'dark':
Logger.info('获取保存的主题: 暗黑');
return ThemeMode.dark;
case 'light':
Logger.info('获取保存的主题: 浅色');
return ThemeMode.light;
}
}
// 回退读取旧版布尔值
final isDarkMode = isSavedDarkMode();
if (_box.hasData(_key)) {
Logger.info('获取保存的主题(兼容旧版): ${isDarkMode ? "暗黑" : "浅色"}');
return isDarkMode ? ThemeMode.dark : ThemeMode.light;
}
// 默认系统跟随
Logger.info('未发现主题偏好,默认系统跟随');
return ThemeMode.system;
} catch (e) {
Logger.error('读取主题模式失败: ${e.toString()}');
return ThemeMode.system;
}
}
/// 是否是暗黑模式
/// 是否是暗黑模式(兼容旧逻辑)
bool isSavedDarkMode() {
try {
final value = _box.read<bool>(_key);
Logger.info('从存储读取主题设置: $value');
Logger.info('从存储读取旧版主题设置: $value');
return value ?? false;
} catch (e) {
Logger.error('读取主题设置失败: ${e.toString()}');
Logger.error('读取旧版主题设置失败: ${e.toString()}');
return false;
}
}
/// 保存主题模式到本地存储
/// 保存主题模式到本地存储(兼容旧方法,同时写入新版字符串键)
Future<void> saveThemeMode(bool isDarkMode) async {
try {
Logger.info('保存主题设置: ${isDarkMode ? "暗黑" : "浅色"}');
await _box.write(_key, isDarkMode);
await _box.write(_modeKey, isDarkMode ? 'dark' : 'light');
} catch (e) {
Logger.error('保存主题设置失败: ${e.toString()}');
}
}
}
/// 新版:显式保存主题模式(system/dark/light)
Future<void> saveThemeModePreference(ThemeMode mode) async {
try {
final String value = mode == ThemeMode.system
? 'system'
: (mode == ThemeMode.dark ? 'dark' : 'light');
Logger.info('保存主题偏好(新版): $value');
await _box.write(_modeKey, value);
// 同步旧键,保持兼容
await _box.write(_key, mode == ThemeMode.dark);
} catch (e) {
Logger.error('保存主题偏好失败: ${e.toString()}');
}
}
}

6
lib/data/services/version_update_service.dart

@ -128,7 +128,7 @@ class VersionUpdateService extends GetxService {
if (response == null || !response.containsKey('app')) {
//[2]获取渠道包信息失败: 响应为空或不包含app字段
_logger.w('获取渠道包信息失败: 响应为空或不包含app字段');
_logger.w('lxm--获取渠道包信息失败: 响应为空或不包含app字段');
return VersionUpdateInfo(
hasUpdate: false,
currentVersion: currentVersion,
@ -153,7 +153,7 @@ class VersionUpdateService extends GetxService {
await _refreshTouristsFromEnv();
}
_logger.d('从服务器获取游客登录配置(最终): ${_isShowTourists}');
_logger.d('lxm--从服务器获取游客登录配置(最终): ${_isShowTourists}');
// if (channelAppResponse.code != 0 || channelAppResponse.data == null) {
// _logger.w('获取版本信息失败: ${channelAppResponse.msg}');
@ -304,7 +304,7 @@ class VersionUpdateService extends GetxService {
final envAppInfo = AppInfo.fromJson(resp['app']);
_isShowTourists = envAppInfo.tourists;
_logger.d(
'lxm--游客登录配置已按.env渠道同步: ${envAppInfo.tourists} (channel=$envChannelName)');
'lxm--游客登录配置已按.env渠道同步: ${envAppInfo.tourists} (channel=$envChannelName),_isShowTourists: $_isShowTourists');
} else {
_logger.w('按.env渠道获取游客配置失败:响应为空或不含app字段');
}

2
lib/modules/login/controllers/login_controller.dart

@ -152,7 +152,7 @@ class LoginController extends GetxController {
try {
_isGuestLoginVisible.value = versionService.cachedShowTourists;
Logger().d('游客登录显示状态: ${_isGuestLoginVisible.value}');
Logger().d('lxm--游客登录显示状态: ${_isGuestLoginVisible.value}');
} catch (e) {
Logger().e('检查游客登录配置失败: $e');
// 默认不显示游客登录

74
lib/modules/picture_translation/views/picture_translation_history_detail_view.dart

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../core/theme/app_colors.dart';
import '../models/picture_translation_models.dart';
@ -17,20 +18,25 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor:
isDarkMode ? AppColors.darkBackground : Colors.grey[50],
appBar: AppBar(
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios,
size: 20.w,
color: Colors.black87,
color: isDarkMode ? AppColors.textPrimary : Colors.black87,
),
onPressed: () => Get.back(),
),
centerTitle: true,
title: const Text('翻译详情'),
backgroundColor: Colors.white,
foregroundColor: Colors.black87,
title: Text('翻译详情',
style: TextStyle(
color: isDarkMode ? AppColors.textPrimary : Colors.black87)),
backgroundColor: isDarkMode ? AppColors.cardBackground : Colors.white,
foregroundColor: isDarkMode ? AppColors.textPrimary : Colors.black87,
elevation: 0,
// actions: [
// IconButton(
@ -65,11 +71,13 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
Widget _buildImageSection() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -85,7 +93,8 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
),
),
),
@ -95,7 +104,8 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.r),
border: Border.all(color: Colors.grey[300]!),
border: Border.all(
color: Get.isDarkMode ? Colors.white12 : Colors.grey[300]!),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8.r),
@ -109,12 +119,12 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.error_outline,
size: 48.sp, color: Colors.red[400]),
size: 48.sp, color: AppColors.error),
SizedBox(height: 8.h),
Text(
'图片加载失败',
style: TextStyle(
fontSize: 14.sp, color: Colors.red[600]),
fontSize: 14.sp, color: AppColors.error),
),
],
),
@ -132,11 +142,13 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
return Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -150,7 +162,11 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
children: [
Text(
'源语言',
style: TextStyle(fontSize: 12.sp, color: Colors.grey[600]),
style: TextStyle(
fontSize: 12.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600]),
),
SizedBox(height: 4.h),
Text(
@ -158,20 +174,25 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.blue,
color: AppColors.primary,
),
),
],
),
),
Icon(Icons.arrow_forward, color: Colors.grey[400]),
Icon(Icons.arrow_forward,
color: Get.isDarkMode ? Colors.white54 : Colors.grey[400]),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'目标语言',
style: TextStyle(fontSize: 12.sp, color: Colors.grey[600]),
style: TextStyle(
fontSize: 12.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600]),
),
SizedBox(height: 4.h),
Text(
@ -179,7 +200,7 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.green,
color: AppColors.success,
),
),
],
@ -194,11 +215,13 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
return Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -235,7 +258,7 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
content,
style: TextStyle(
fontSize: 15.sp,
color: Colors.black87,
color: Get.isDarkMode ? Colors.white70 : Colors.black87,
height: 1.5,
),
),
@ -248,11 +271,13 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
return Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -266,7 +291,8 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
),
),
SizedBox(height: 8.h),
@ -274,7 +300,7 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
_formatDateTime(item.timestamp),
style: TextStyle(
fontSize: 14.sp,
color: Colors.grey[600],
color: Get.isDarkMode ? AppColors.textSecondary : Colors.grey[600],
),
),
],

267
lib/modules/picture_translation/views/picture_translation_view.dart

@ -21,7 +21,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return Scaffold(
backgroundColor: Colors.grey[50],
backgroundColor:
isDarkMode ? AppColors.darkBackground : Colors.grey[50],
appBar: _buildAppBar(isDarkMode),
body: SafeArea(
child: Obx(() {
@ -140,11 +141,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
return Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -158,7 +161,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
),
),
SizedBox(height: 12.h),
@ -195,8 +199,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
required VoidCallback onTap,
required Color color,
}) {
final isDarkMode = Get.isDarkMode;
return Material(
color: color.withOpacity(0.1),
color: color.withOpacity(isDarkMode ? 0.2 : 0.1),
borderRadius: BorderRadius.circular(8.r),
child: InkWell(
onTap: controller.isProcessing.value ? null : onTap,
@ -254,11 +259,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Widget _buildImageSection() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -274,7 +281,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
),
),
),
@ -289,11 +297,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
return Container(
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -315,15 +325,21 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
color: Get.isDarkMode
? AppColors.textPrimary
: Colors.black87,
),
),
if (step.description.isNotEmpty) ...[
SizedBox(height: 4.h),
Text(
step.description,
style:
TextStyle(fontSize: 14.sp, color: Colors.grey[600]),
style: TextStyle(
fontSize: 14.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600],
),
),
],
],
@ -335,7 +351,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
SizedBox(height: 12.h),
LinearProgressIndicator(
value: step.progress,
backgroundColor: Colors.grey[200],
backgroundColor:
Get.isDarkMode ? Colors.white12 : Colors.grey[200],
valueColor:
AlwaysStoppedAnimation<Color>(_getStatusColor(step.status)),
),
@ -360,38 +377,41 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
),
);
case ProcessingStatus.error:
return Icon(Icons.error_outline, color: Colors.red, size: 20.sp);
return Icon(Icons.error_outline,
color: AppColors.error, size: 20.sp);
case ProcessingStatus.idle:
return Icon(Icons.check_circle_outline,
color: Colors.green, size: 20.sp);
color: AppColors.success, size: 20.sp);
}
}
Color _getStatusColor(ProcessingStatus status) {
switch (status) {
case ProcessingStatus.picking:
return Colors.blue;
return AppColors.primary;
case ProcessingStatus.recognizing:
return Colors.orange;
return AppColors.warning;
case ProcessingStatus.translating:
return Colors.purple;
return AppColors.accent;
case ProcessingStatus.saving:
return Colors.green;
return AppColors.success;
case ProcessingStatus.error:
return Colors.red;
return AppColors.error;
case ProcessingStatus.idle:
return Colors.grey;
return AppColors.disabled;
}
}
Widget _buildResultsSection() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -407,7 +427,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
),
),
),
@ -428,24 +449,28 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
if (controller.translatedImageBytes.value != null) ...[
Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Text(
'翻译后的图片预览',
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
),
child: Text(
'翻译后的图片预览',
style: TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.w600,
color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
),
),
SizedBox(height: 8.h),
Container(
height: 200.h,
margin:
EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
decoration: BoxDecoration(
color: Colors.grey[100],
),
SizedBox(height: 8.h),
Container(
height: 200.h,
margin:
EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
decoration: BoxDecoration(
color: Get.isDarkMode
? AppColors.cardBackground
: Colors.grey[100],
borderRadius: BorderRadius.circular(8.r),
border: Border.all(color: Colors.grey[300]!),
border: Border.all(
color: Get.isDarkMode ? Colors.white12 : Colors.grey[300]!),
),
child: GestureDetector(
onTap: () => _openImageViewer(
@ -490,9 +515,10 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
margin: EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
padding: EdgeInsets.all(16.w),
decoration: BoxDecoration(
color: color.withOpacity(0.05),
color: color.withOpacity(Get.isDarkMode ? 0.15 : 0.05),
borderRadius: BorderRadius.circular(8.r),
border: Border.all(color: color.withOpacity(0.2)),
border: Border.all(
color: color.withOpacity(Get.isDarkMode ? 0.3 : 0.2)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@ -523,8 +549,11 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
SizedBox(height: 8.h),
SelectableText(
content,
style:
TextStyle(fontSize: 15.sp, color: Colors.black87, height: 1.4),
style: TextStyle(
fontSize: 15.sp,
color:
Get.isDarkMode ? Colors.white70 : Colors.black87,
height: 1.4),
),
],
),
@ -534,11 +563,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Widget _buildHistorySection() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
@ -557,7 +588,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle(
fontSize: 16.sp,
fontWeight: FontWeight.w600,
color: Colors.black87,
color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
),
),
TextButton(
@ -573,7 +605,11 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
child: Text(
'noTranslationHistory'.tr, // 翻译键代表的中文文本内容
style: TextStyle(fontSize: 14.sp, color: Colors.grey[600]),
style: TextStyle(
fontSize: 14.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600]),
),
)
else
@ -593,8 +629,10 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
child: Container(
width: 40.w,
height: 40.w,
color: Colors.grey[200],
child: Icon(Icons.image, color: Colors.grey[400]),
color:
Get.isDarkMode ? Colors.white.withOpacity(0.05) : Colors.grey[200],
child: Icon(Icons.image,
color: Get.isDarkMode ? Colors.white70 : Colors.grey[400]),
),
),
title: Text(
@ -605,11 +643,17 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
),
subtitle: Text(
'${item.sourceLanguageName} → ${item.targetLanguageName}',
style: TextStyle(fontSize: 12.sp, color: Colors.grey[600]),
style: TextStyle(
fontSize: 12.sp,
color:
Get.isDarkMode ? AppColors.textSecondary : Colors.grey[600]),
),
trailing: Text(
_formatTime(item.timestamp),
style: TextStyle(fontSize: 12.sp, color: Colors.grey[500]),
style: TextStyle(
fontSize: 12.sp,
color:
Get.isDarkMode ? Colors.white54 : Colors.grey[500]),
),
onTap: () => _showHistoryDetail(item),
);
@ -620,7 +664,7 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Container(
height: 600.h,
decoration: BoxDecoration(
color: Colors.white,
color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)),
),
child: Column(
@ -632,12 +676,18 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
children: [
Text(
'translationHistory'.tr, // 翻译键代表的中文文本内容
style:
TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold),
style: TextStyle(
fontSize: 18.sp,
fontWeight: FontWeight.bold,
color: Get.isDarkMode
? AppColors.textPrimary
: null),
),
IconButton(
onPressed: () => Get.back(),
icon: const Icon(Icons.close),
icon: Icon(Icons.close,
color:
Get.isDarkMode ? AppColors.textPrimary : null),
),
],
),
@ -649,8 +699,11 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
return Center(
child: Text(
'noTranslationHistory'.tr, // 翻译键代表的中文文本内容
style:
TextStyle(fontSize: 16.sp, color: Colors.grey[600]),
style: TextStyle(
fontSize: 16.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600]),
),
);
}
@ -705,25 +758,44 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
void _showSettingsDialog() {
Get.dialog(
AlertDialog(
title: const Text('设置'),
backgroundColor: Get.isDarkMode ? Colors.grey[900] : Colors.white,
title: Text('设置',
style: TextStyle(
color: Get.isDarkMode ? Colors.white : Colors.black87)),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.photo_size_select_actual),
title: const Text('图片质量'),
leading: Icon(Icons.photo_size_select_actual,
color: Get.isDarkMode ? Colors.white : null),
title: Text('图片质量',
style: TextStyle(
color:
Get.isDarkMode ? Colors.white : Colors.black87)),
subtitle:
Obx(() => Text('当前: ${controller.imageQuality.value}%')),
Obx(() => Text('当前: ${controller.imageQuality.value}%',
style: TextStyle(
color: Get.isDarkMode
? Colors.white70
: Colors.black54))),
onTap: () {
Get.back();
_showImageQualityDialog();
},
),
ListTile(
leading: const Icon(Icons.photo_size_select_large),
title: const Text('最大尺寸'),
leading: Icon(Icons.photo_size_select_large,
color: Get.isDarkMode ? Colors.white : null),
title: Text('最大尺寸',
style: TextStyle(
color:
Get.isDarkMode ? Colors.white : Colors.black87)),
subtitle:
Obx(() => Text('当前: ${controller.maxImageSize.value}px')),
Obx(() => Text('当前: ${controller.maxImageSize.value}px',
style: TextStyle(
color: Get.isDarkMode
? Colors.white70
: Colors.black54))),
onTap: () {
Get.back();
_showImageSizeDialog();
@ -734,7 +806,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
actions: [
TextButton(
onPressed: () => Get.back(),
child: const Text('关闭'),
child: Text('关闭',
style: TextStyle(
color: Get.isDarkMode ? Colors.white70 : Colors.black54)),
),
],
),
@ -744,11 +818,17 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
void _showImageQualityDialog() {
Get.dialog(
AlertDialog(
title: const Text('设置图片质量'),
backgroundColor: Get.isDarkMode ? Colors.grey[900] : Colors.white,
title: Text('设置图片质量',
style: TextStyle(
color: Get.isDarkMode ? Colors.white : Colors.black87)),
content: Obx(() => Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('当前质量: ${controller.imageQuality.value}%'),
Text('当前质量: ${controller.imageQuality.value}%',
style: TextStyle(
color:
Get.isDarkMode ? Colors.white70 : Colors.black54)),
Slider(
value: controller.imageQuality.value.toDouble(),
min: 50,
@ -763,7 +843,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
actions: [
TextButton(
onPressed: () => Get.back(),
child: const Text('确定'),
child: Text('确定',
style: TextStyle(
color: Get.isDarkMode ? Colors.white70 : Colors.black54)),
),
],
),
@ -774,7 +856,10 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
final sizes = [1280, 1920, 2560, 3840];
Get.dialog(
AlertDialog(
title: const Text('设置最大尺寸'),
backgroundColor: Get.isDarkMode ? Colors.grey[900] : Colors.white,
title: Text('设置最大尺寸',
style: TextStyle(
color: Get.isDarkMode ? Colors.white : Colors.black87)),
content: Column(
mainAxisSize: MainAxisSize.min,
children: sizes
@ -794,7 +879,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
actions: [
TextButton(
onPressed: () => Get.back(),
child: const Text('取消'),
child: Text('取消',
style: TextStyle(
color: Get.isDarkMode ? Colors.white70 : Colors.black54)),
),
],
),
@ -804,19 +891,26 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
void _showClearHistoryDialog() {
Get.dialog(
AlertDialog(
title: const Text('清空历史'),
content: const Text('确定要清空所有翻译历史吗?此操作不可撤销。'),
backgroundColor: Get.isDarkMode ? Colors.grey[900] : Colors.white,
title: Text('清空历史',
style: TextStyle(
color: Get.isDarkMode ? Colors.white : Colors.black87)),
content: Text('确定要清空所有翻译历史吗?此操作不可撤销。',
style: TextStyle(
color: Get.isDarkMode ? Colors.white70 : Colors.black54)),
actions: [
TextButton(
onPressed: () => Get.back(),
child: const Text('取消'),
child: Text('取消',
style: TextStyle(
color: Get.isDarkMode ? Colors.white70 : Colors.black54)),
),
TextButton(
onPressed: () {
controller.clearHistory();
Get.back();
},
child: Text('确定', style: TextStyle(color: Colors.red)),
child: Text('确定', style: TextStyle(color: AppColors.error)),
),
],
),
@ -829,9 +923,11 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
height: 200.h,
margin: EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
decoration: BoxDecoration(
color: Colors.grey[100],
color:
Get.isDarkMode ? AppColors.cardBackground : Colors.grey[100],
borderRadius: BorderRadius.circular(8.r),
border: Border.all(color: Colors.grey[300]!),
border:
Border.all(color: Get.isDarkMode ? Colors.white12 : Colors.grey[300]!),
),
child: file == null
? Center(
@ -839,11 +935,16 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.image_outlined,
size: 48.sp, color: Colors.grey[400]),
size: 48.sp,
color: Get.isDarkMode ? Colors.white54 : Colors.grey[400]),
SizedBox(height: 8.h),
Text(
'请选择图片',
style: TextStyle(fontSize: 14.sp, color: Colors.grey[600]),
style: TextStyle(
fontSize: 14.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600]),
),
],
),
@ -868,7 +969,10 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Text(
'图片加载失败',
style: TextStyle(
fontSize: 14.sp, color: Colors.grey[600]),
fontSize: 14.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600]),
),
],
),
@ -893,7 +997,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
padding: EdgeInsets.all(12.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.r),
border: Border.all(color: Colors.grey.shade300),
border: Border.all(
color: Get.isDarkMode ? Colors.white12 : Colors.grey.shade300),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,

Loading…
Cancel
Save