Browse Source

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

refactor: 重构主题服务以支持系统/浅色/深色三种模式
style: 为图片翻译模块添加暗黑模式样式支持
chore: 在日志信息中添加开发者前缀
newdev_shunjiawei
lxm 12 months ago
parent
commit
d3b4a7a3f8
  1. 62
      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

62
lib/core/themes/theme_service.dart

@ -5,34 +5,80 @@ import '../../core/utils/logger.dart';
class ThemeService { class ThemeService {
final _box = GetStorage(); final _box = GetStorage();
// 旧版布尔键,兼容历史数据
final _key = 'isDarkMode'; final _key = 'isDarkMode';
// 新版字符串键,支持系统跟随/深色/浅色
final _modeKey = 'themeModePreference';
/// 获取主题模式 /// 获取主题模式(优先读取新版字符串偏好;否则回退到旧版布尔值;都没有则跟随系统)
ThemeMode getThemeMode() { ThemeMode getThemeMode() {
final isDarkMode = isSavedDarkMode(); try {
Logger.info('获取保存的主题: ${isDarkMode ? "暗黑" : "浅色"}'); final String? pref = _box.read<String>(_modeKey);
return isDarkMode ? ThemeMode.dark : ThemeMode.light; 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() { bool isSavedDarkMode() {
try { try {
final value = _box.read<bool>(_key); final value = _box.read<bool>(_key);
Logger.info('从存储读取主题设置: $value'); Logger.info('从存储读取旧版主题设置: $value');
return value ?? false; return value ?? false;
} catch (e) { } catch (e) {
Logger.error('读取主题设置失败: ${e.toString()}'); Logger.error('读取旧版主题设置失败: ${e.toString()}');
return false; return false;
} }
} }
/// 保存主题模式到本地存储 /// 保存主题模式到本地存储(兼容旧方法,同时写入新版字符串键)
Future<void> saveThemeMode(bool isDarkMode) async { Future<void> saveThemeMode(bool isDarkMode) async {
try { try {
Logger.info('保存主题设置: ${isDarkMode ? "暗黑" : "浅色"}'); Logger.info('保存主题设置: ${isDarkMode ? "暗黑" : "浅色"}');
await _box.write(_key, isDarkMode); await _box.write(_key, isDarkMode);
await _box.write(_modeKey, isDarkMode ? 'dark' : 'light');
} catch (e) { } catch (e) {
Logger.error('保存主题设置失败: ${e.toString()}'); 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')) { if (response == null || !response.containsKey('app')) {
//[2]获取渠道包信息失败: 响应为空或不包含app字段 //[2]获取渠道包信息失败: 响应为空或不包含app字段
_logger.w('获取渠道包信息失败: 响应为空或不包含app字段'); _logger.w('lxm--获取渠道包信息失败: 响应为空或不包含app字段');
return VersionUpdateInfo( return VersionUpdateInfo(
hasUpdate: false, hasUpdate: false,
currentVersion: currentVersion, currentVersion: currentVersion,
@ -153,7 +153,7 @@ class VersionUpdateService extends GetxService {
await _refreshTouristsFromEnv(); await _refreshTouristsFromEnv();
} }
_logger.d('从服务器获取游客登录配置(最终): ${_isShowTourists}'); _logger.d('lxm--从服务器获取游客登录配置(最终): ${_isShowTourists}');
// if (channelAppResponse.code != 0 || channelAppResponse.data == null) { // if (channelAppResponse.code != 0 || channelAppResponse.data == null) {
// _logger.w('获取版本信息失败: ${channelAppResponse.msg}'); // _logger.w('获取版本信息失败: ${channelAppResponse.msg}');
@ -304,7 +304,7 @@ class VersionUpdateService extends GetxService {
final envAppInfo = AppInfo.fromJson(resp['app']); final envAppInfo = AppInfo.fromJson(resp['app']);
_isShowTourists = envAppInfo.tourists; _isShowTourists = envAppInfo.tourists;
_logger.d( _logger.d(
'lxm--游客登录配置已按.env渠道同步: ${envAppInfo.tourists} (channel=$envChannelName)'); 'lxm--游客登录配置已按.env渠道同步: ${envAppInfo.tourists} (channel=$envChannelName),_isShowTourists: $_isShowTourists');
} else { } else {
_logger.w('按.env渠道获取游客配置失败:响应为空或不含app字段'); _logger.w('按.env渠道获取游客配置失败:响应为空或不含app字段');
} }

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

@ -152,7 +152,7 @@ class LoginController extends GetxController {
try { try {
_isGuestLoginVisible.value = versionService.cachedShowTourists; _isGuestLoginVisible.value = versionService.cachedShowTourists;
Logger().d('游客登录显示状态: ${_isGuestLoginVisible.value}'); Logger().d('lxm--游客登录显示状态: ${_isGuestLoginVisible.value}');
} catch (e) { } catch (e) {
Logger().e('检查游客登录配置失败: $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:flutter/services.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../../core/theme/app_colors.dart';
import '../models/picture_translation_models.dart'; import '../models/picture_translation_models.dart';
@ -17,20 +18,25 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return Scaffold( return Scaffold(
backgroundColor:
isDarkMode ? AppColors.darkBackground : Colors.grey[50],
appBar: AppBar( appBar: AppBar(
leading: IconButton( leading: IconButton(
icon: Icon( icon: Icon(
Icons.arrow_back_ios, Icons.arrow_back_ios,
size: 20.w, size: 20.w,
color: Colors.black87, color: isDarkMode ? AppColors.textPrimary : Colors.black87,
), ),
onPressed: () => Get.back(), onPressed: () => Get.back(),
), ),
centerTitle: true, centerTitle: true,
title: const Text('翻译详情'), title: Text('翻译详情',
backgroundColor: Colors.white, style: TextStyle(
foregroundColor: Colors.black87, color: isDarkMode ? AppColors.textPrimary : Colors.black87)),
backgroundColor: isDarkMode ? AppColors.cardBackground : Colors.white,
foregroundColor: isDarkMode ? AppColors.textPrimary : Colors.black87,
elevation: 0, elevation: 0,
// actions: [ // actions: [
// IconButton( // IconButton(
@ -65,11 +71,13 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
Widget _buildImageSection() { Widget _buildImageSection() {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -85,7 +93,8 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, 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), EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.r), 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( child: ClipRRect(
borderRadius: BorderRadius.circular(8.r), borderRadius: BorderRadius.circular(8.r),
@ -109,12 +119,12 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(Icons.error_outline, Icon(Icons.error_outline,
size: 48.sp, color: Colors.red[400]), size: 48.sp, color: AppColors.error),
SizedBox(height: 8.h), SizedBox(height: 8.h),
Text( Text(
'图片加载失败', '图片加载失败',
style: TextStyle( 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( return Container(
padding: EdgeInsets.all(16.w), padding: EdgeInsets.all(16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -150,7 +162,11 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
children: [ children: [
Text( 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), SizedBox(height: 4.h),
Text( Text(
@ -158,20 +174,25 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, 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( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Text( 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), SizedBox(height: 4.h),
Text( Text(
@ -179,7 +200,7 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.green, color: AppColors.success,
), ),
), ),
], ],
@ -194,11 +215,13 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
return Container( return Container(
padding: EdgeInsets.all(16.w), padding: EdgeInsets.all(16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -235,7 +258,7 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
content, content,
style: TextStyle( style: TextStyle(
fontSize: 15.sp, fontSize: 15.sp,
color: Colors.black87, color: Get.isDarkMode ? Colors.white70 : Colors.black87,
height: 1.5, height: 1.5,
), ),
), ),
@ -248,11 +271,13 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
return Container( return Container(
padding: EdgeInsets.all(16.w), padding: EdgeInsets.all(16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -266,7 +291,8 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.black87, color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
), ),
), ),
SizedBox(height: 8.h), SizedBox(height: 8.h),
@ -274,7 +300,7 @@ class PictureTranslationHistoryDetailView extends StatelessWidget {
_formatDateTime(item.timestamp), _formatDateTime(item.timestamp),
style: TextStyle( style: TextStyle(
fontSize: 14.sp, 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) { Widget build(BuildContext context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark; final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return Scaffold( return Scaffold(
backgroundColor: Colors.grey[50], backgroundColor:
isDarkMode ? AppColors.darkBackground : Colors.grey[50],
appBar: _buildAppBar(isDarkMode), appBar: _buildAppBar(isDarkMode),
body: SafeArea( body: SafeArea(
child: Obx(() { child: Obx(() {
@ -140,11 +141,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
return Container( return Container(
padding: EdgeInsets.all(16.w), padding: EdgeInsets.all(16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -158,7 +161,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.black87, color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
), ),
), ),
SizedBox(height: 12.h), SizedBox(height: 12.h),
@ -195,8 +199,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
required VoidCallback onTap, required VoidCallback onTap,
required Color color, required Color color,
}) { }) {
final isDarkMode = Get.isDarkMode;
return Material( return Material(
color: color.withOpacity(0.1), color: color.withOpacity(isDarkMode ? 0.2 : 0.1),
borderRadius: BorderRadius.circular(8.r), borderRadius: BorderRadius.circular(8.r),
child: InkWell( child: InkWell(
onTap: controller.isProcessing.value ? null : onTap, onTap: controller.isProcessing.value ? null : onTap,
@ -254,11 +259,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Widget _buildImageSection() { Widget _buildImageSection() {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -274,7 +281,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.black87, color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
), ),
), ),
), ),
@ -289,11 +297,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
return Container( return Container(
padding: EdgeInsets.all(16.w), padding: EdgeInsets.all(16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -315,15 +325,21 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.black87, color: Get.isDarkMode
? AppColors.textPrimary
: Colors.black87,
), ),
), ),
if (step.description.isNotEmpty) ...[ if (step.description.isNotEmpty) ...[
SizedBox(height: 4.h), SizedBox(height: 4.h),
Text( Text(
step.description, step.description,
style: style: TextStyle(
TextStyle(fontSize: 14.sp, color: Colors.grey[600]), fontSize: 14.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600],
),
), ),
], ],
], ],
@ -335,7 +351,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
SizedBox(height: 12.h), SizedBox(height: 12.h),
LinearProgressIndicator( LinearProgressIndicator(
value: step.progress, value: step.progress,
backgroundColor: Colors.grey[200], backgroundColor:
Get.isDarkMode ? Colors.white12 : Colors.grey[200],
valueColor: valueColor:
AlwaysStoppedAnimation<Color>(_getStatusColor(step.status)), AlwaysStoppedAnimation<Color>(_getStatusColor(step.status)),
), ),
@ -360,38 +377,41 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
), ),
); );
case ProcessingStatus.error: 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: case ProcessingStatus.idle:
return Icon(Icons.check_circle_outline, return Icon(Icons.check_circle_outline,
color: Colors.green, size: 20.sp); color: AppColors.success, size: 20.sp);
} }
} }
Color _getStatusColor(ProcessingStatus status) { Color _getStatusColor(ProcessingStatus status) {
switch (status) { switch (status) {
case ProcessingStatus.picking: case ProcessingStatus.picking:
return Colors.blue; return AppColors.primary;
case ProcessingStatus.recognizing: case ProcessingStatus.recognizing:
return Colors.orange; return AppColors.warning;
case ProcessingStatus.translating: case ProcessingStatus.translating:
return Colors.purple; return AppColors.accent;
case ProcessingStatus.saving: case ProcessingStatus.saving:
return Colors.green; return AppColors.success;
case ProcessingStatus.error: case ProcessingStatus.error:
return Colors.red; return AppColors.error;
case ProcessingStatus.idle: case ProcessingStatus.idle:
return Colors.grey; return AppColors.disabled;
} }
} }
Widget _buildResultsSection() { Widget _buildResultsSection() {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -407,7 +427,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, 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) ...[ if (controller.translatedImageBytes.value != null) ...[
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 16.w), padding: EdgeInsets.symmetric(horizontal: 16.w),
child: Text( child: Text(
'翻译后的图片预览', '翻译后的图片预览',
style: TextStyle( style: TextStyle(
fontSize: 14.sp, fontSize: 14.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.black87, color:
), Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
), ),
), ),
SizedBox(height: 8.h), ),
Container( SizedBox(height: 8.h),
height: 200.h, Container(
margin: height: 200.h,
EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h), margin:
decoration: BoxDecoration( EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
color: Colors.grey[100], decoration: BoxDecoration(
color: Get.isDarkMode
? AppColors.cardBackground
: Colors.grey[100],
borderRadius: BorderRadius.circular(8.r), 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( child: GestureDetector(
onTap: () => _openImageViewer( onTap: () => _openImageViewer(
@ -490,9 +515,10 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
margin: EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h), margin: EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
padding: EdgeInsets.all(16.w), padding: EdgeInsets.all(16.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: color.withOpacity(0.05), color: color.withOpacity(Get.isDarkMode ? 0.15 : 0.05),
borderRadius: BorderRadius.circular(8.r), 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( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -523,8 +549,11 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
SizedBox(height: 8.h), SizedBox(height: 8.h),
SelectableText( SelectableText(
content, content,
style: style: TextStyle(
TextStyle(fontSize: 15.sp, color: Colors.black87, height: 1.4), fontSize: 15.sp,
color:
Get.isDarkMode ? Colors.white70 : Colors.black87,
height: 1.4),
), ),
], ],
), ),
@ -534,11 +563,13 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Widget _buildHistorySection() { Widget _buildHistorySection() {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.circular(12.r), borderRadius: BorderRadius.circular(12.r),
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: Colors.black.withOpacity(0.05), color: Get.isDarkMode
? Colors.black.withOpacity(0.2)
: Colors.black.withOpacity(0.05),
blurRadius: 10, blurRadius: 10,
offset: const Offset(0, 2), offset: const Offset(0, 2),
), ),
@ -557,7 +588,8 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
style: TextStyle( style: TextStyle(
fontSize: 16.sp, fontSize: 16.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
color: Colors.black87, color:
Get.isDarkMode ? AppColors.textPrimary : Colors.black87,
), ),
), ),
TextButton( TextButton(
@ -573,7 +605,11 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h), EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
child: Text( child: Text(
'noTranslationHistory'.tr, // 翻译键代表的中文文本内容 '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 else
@ -593,8 +629,10 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
child: Container( child: Container(
width: 40.w, width: 40.w,
height: 40.w, height: 40.w,
color: Colors.grey[200], color:
child: Icon(Icons.image, color: Colors.grey[400]), Get.isDarkMode ? Colors.white.withOpacity(0.05) : Colors.grey[200],
child: Icon(Icons.image,
color: Get.isDarkMode ? Colors.white70 : Colors.grey[400]),
), ),
), ),
title: Text( title: Text(
@ -605,11 +643,17 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
), ),
subtitle: Text( subtitle: Text(
'${item.sourceLanguageName} → ${item.targetLanguageName}', '${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( trailing: Text(
_formatTime(item.timestamp), _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), onTap: () => _showHistoryDetail(item),
); );
@ -620,7 +664,7 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
Container( Container(
height: 600.h, height: 600.h,
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Get.isDarkMode ? AppColors.cardBackground : Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)), borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)),
), ),
child: Column( child: Column(
@ -632,12 +676,18 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
children: [ children: [
Text( Text(
'translationHistory'.tr, // 翻译键代表的中文文本内容 'translationHistory'.tr, // 翻译键代表的中文文本内容
style: style: TextStyle(
TextStyle(fontSize: 18.sp, fontWeight: FontWeight.bold), fontSize: 18.sp,
fontWeight: FontWeight.bold,
color: Get.isDarkMode
? AppColors.textPrimary
: null),
), ),
IconButton( IconButton(
onPressed: () => Get.back(), 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( return Center(
child: Text( child: Text(
'noTranslationHistory'.tr, // 翻译键代表的中文文本内容 'noTranslationHistory'.tr, // 翻译键代表的中文文本内容
style: style: TextStyle(
TextStyle(fontSize: 16.sp, color: Colors.grey[600]), fontSize: 16.sp,
color: Get.isDarkMode
? AppColors.textSecondary
: Colors.grey[600]),
), ),
); );
} }
@ -705,25 +758,44 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
void _showSettingsDialog() { void _showSettingsDialog() {
Get.dialog( Get.dialog(
AlertDialog( 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( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
ListTile( ListTile(
leading: const Icon(Icons.photo_size_select_actual), leading: Icon(Icons.photo_size_select_actual,
title: const Text('图片质量'), color: Get.isDarkMode ? Colors.white : null),
title: Text('图片质量',
style: TextStyle(
color:
Get.isDarkMode ? Colors.white : Colors.black87)),
subtitle: subtitle:
Obx(() => Text('当前: ${controller.imageQuality.value}%')), Obx(() => Text('当前: ${controller.imageQuality.value}%',
style: TextStyle(
color: Get.isDarkMode
? Colors.white70
: Colors.black54))),
onTap: () { onTap: () {
Get.back(); Get.back();
_showImageQualityDialog(); _showImageQualityDialog();
}, },
), ),
ListTile( ListTile(
leading: const Icon(Icons.photo_size_select_large), leading: Icon(Icons.photo_size_select_large,
title: const Text('最大尺寸'), color: Get.isDarkMode ? Colors.white : null),
title: Text('最大尺寸',
style: TextStyle(
color:
Get.isDarkMode ? Colors.white : Colors.black87)),
subtitle: subtitle:
Obx(() => Text('当前: ${controller.maxImageSize.value}px')), Obx(() => Text('当前: ${controller.maxImageSize.value}px',
style: TextStyle(
color: Get.isDarkMode
? Colors.white70
: Colors.black54))),
onTap: () { onTap: () {
Get.back(); Get.back();
_showImageSizeDialog(); _showImageSizeDialog();
@ -734,7 +806,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Get.back(), 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() { void _showImageQualityDialog() {
Get.dialog( Get.dialog(
AlertDialog( 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( content: Obx(() => Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text('当前质量: ${controller.imageQuality.value}%'), Text('当前质量: ${controller.imageQuality.value}%',
style: TextStyle(
color:
Get.isDarkMode ? Colors.white70 : Colors.black54)),
Slider( Slider(
value: controller.imageQuality.value.toDouble(), value: controller.imageQuality.value.toDouble(),
min: 50, min: 50,
@ -763,7 +843,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Get.back(), 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]; final sizes = [1280, 1920, 2560, 3840];
Get.dialog( Get.dialog(
AlertDialog( 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( content: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: sizes children: sizes
@ -794,7 +879,9 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Get.back(), 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() { void _showClearHistoryDialog() {
Get.dialog( Get.dialog(
AlertDialog( AlertDialog(
title: const Text('清空历史'), backgroundColor: Get.isDarkMode ? Colors.grey[900] : Colors.white,
content: const Text('确定要清空所有翻译历史吗?此操作不可撤销。'), title: Text('清空历史',
style: TextStyle(
color: Get.isDarkMode ? Colors.white : Colors.black87)),
content: Text('确定要清空所有翻译历史吗?此操作不可撤销。',
style: TextStyle(
color: Get.isDarkMode ? Colors.white70 : Colors.black54)),
actions: [ actions: [
TextButton( TextButton(
onPressed: () => Get.back(), onPressed: () => Get.back(),
child: const Text('取消'), child: Text('取消',
style: TextStyle(
color: Get.isDarkMode ? Colors.white70 : Colors.black54)),
), ),
TextButton( TextButton(
onPressed: () { onPressed: () {
controller.clearHistory(); controller.clearHistory();
Get.back(); 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, height: 200.h,
margin: EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h), margin: EdgeInsets.symmetric(horizontal: 16.w).copyWith(bottom: 16.h),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.grey[100], color:
Get.isDarkMode ? AppColors.cardBackground : Colors.grey[100],
borderRadius: BorderRadius.circular(8.r), 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 child: file == null
? Center( ? Center(
@ -839,11 +935,16 @@ class PictureTranslationView extends GetView<PictureTranslationController> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Icon(Icons.image_outlined, 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), SizedBox(height: 8.h),
Text( 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( Text(
'图片加载失败', '图片加载失败',
style: TextStyle( 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), padding: EdgeInsets.all(12.w),
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8.r), 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( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,

Loading…
Cancel
Save