适配深色模式

This commit is contained in:
DelLevin-Home
2026-05-26 05:10:21 +08:00
parent b36f50827f
commit 73f3795e65
53 changed files with 3846 additions and 3211 deletions

View File

@@ -40,71 +40,74 @@ class _BackupPageState extends State<BackupPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(
title: const Text('本地备份'),
),
body: _isLoading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(24),
children: [
// 自动备份开关 - 紧凑一行
_buildAutoBackupSection(),
padding: const EdgeInsets.all(24),
children: [
// 自动备份开关 - 紧凑一行
_buildAutoBackupSection(colors),
const SizedBox(height: 24),
const SizedBox(height: 24),
// 手动备份
_buildSectionTitle('手动备份'),
const SizedBox(height: 12),
_buildActionCard(
title: '导出数据',
description: '将所有数据导出为 zip 文件,可用于备份或迁移到其他设备',
icon: Icons.upload_outlined,
buttonText: '导出',
isLoading: _isExporting,
onTap: _exportData,
),
const SizedBox(height: 12),
_buildActionCard(
title: '导入数据',
description: '从备份文件导入数据,将覆盖当前所有数据',
icon: Icons.download_outlined,
buttonText: '导入',
isLoading: _isImporting,
onTap: _importData,
isDestructive: true,
),
// 手动备份
_buildSectionTitle(colors, '手动备份'),
const SizedBox(height: 12),
_buildActionCard(
colors: colors,
title: '导出数据',
description: '将所有数据导出为 zip 文件,可用于备份或迁移到其他设备',
icon: Icons.upload_outlined,
buttonText: '导出',
isLoading: _isExporting,
onTap: _exportData,
),
const SizedBox(height: 12),
_buildActionCard(
colors: colors,
title: '导入数据',
description: '从备份文件导入数据,将覆盖当前所有数据',
icon: Icons.download_outlined,
buttonText: '导入',
isLoading: _isImporting,
onTap: _importData,
isDestructive: true,
),
const SizedBox(height: 32),
const SizedBox(height: 32),
// 使用说明
_buildInfoSection(),
],
),
// 使用说明
_buildInfoSection(colors),
],
),
);
}
/// 构建区块标题
Widget _buildSectionTitle(String title) {
Widget _buildSectionTitle(ColorScheme colors, String title) {
return Row(
children: [
Container(
width: 4,
height: 16,
decoration: BoxDecoration(
color: const Color(0xFF1A1A1A),
color: colors.primary,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 8),
Text(
title,
style: const TextStyle(
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
],
@@ -113,6 +116,7 @@ class _BackupPageState extends State<BackupPage> {
/// 构建操作卡片
Widget _buildActionCard({
required ColorScheme colors,
required String title,
required String description,
required IconData icon,
@@ -124,7 +128,7 @@ class _BackupPageState extends State<BackupPage> {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: const Color(0xFFFAFAFA),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
),
child: Column(
@@ -136,19 +140,17 @@ class _BackupPageState extends State<BackupPage> {
width: 44,
height: 44,
decoration: BoxDecoration(
color: Colors.white,
color: colors.surface,
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: isDestructive
? Colors.red.withOpacity(0.3)
: const Color(0xFFE8E8E8),
color: isDestructive ? Colors.red.withOpacity(0.3) : colors.outline,
width: 0.5,
),
),
child: Icon(
icon,
size: 22,
color: isDestructive ? Colors.red : const Color(0xFF666666),
color: isDestructive ? Colors.red : colors.onSurface.withValues(alpha: 0.6),
),
),
const SizedBox(width: 16),
@@ -158,18 +160,18 @@ class _BackupPageState extends State<BackupPage> {
children: [
Text(
title,
style: const TextStyle(
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
const SizedBox(height: 4),
Text(
description,
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
height: 1.4,
),
),
@@ -185,25 +187,25 @@ class _BackupPageState extends State<BackupPage> {
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 14),
decoration: BoxDecoration(
color: isLoading ? const Color(0xFFCCCCCC) : const Color(0xFF1A1A1A),
color: isLoading ? colors.onSurface.withValues(alpha: 0.25) : colors.primary,
borderRadius: BorderRadius.circular(8),
),
child: Center(
child: isLoading
? const SizedBox(
? SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation(Colors.white),
valueColor: AlwaysStoppedAnimation(colors.onPrimary),
),
)
: Text(
buttonText,
style: const TextStyle(
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w500,
color: Colors.white,
color: colors.onPrimary,
),
),
),
@@ -215,11 +217,11 @@ class _BackupPageState extends State<BackupPage> {
}
/// 构建信息说明区域
Widget _buildInfoSection() {
Widget _buildInfoSection(ColorScheme colors) {
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: const Color(0xFFF8F8F8),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
),
child: Column(
@@ -231,42 +233,42 @@ class _BackupPageState extends State<BackupPage> {
width: 32,
height: 32,
decoration: BoxDecoration(
color: Colors.white,
color: colors.surface,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
border: Border.all(color: colors.outline, width: 0.5),
),
child: const Icon(
child: Icon(
Icons.info_outline,
size: 18,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
),
const SizedBox(width: 12),
const Text(
Text(
'使用说明',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Color(0xFF1A1A1A),
color: colors.onSurface,
),
),
],
),
const SizedBox(height: 16),
_buildInfoItem('1', '导出数据会生成一个 .zip 文件,包含所有数据和图片'),
_buildInfoItem(colors, '1', '导出数据会生成一个 .zip 文件,包含所有数据和图片'),
const SizedBox(height: 12),
_buildInfoItem('2', '选择保存路径后,可以通过微信、邮件等方式发送备份文件'),
_buildInfoItem(colors, '2', '选择保存路径后,可以通过微信、邮件等方式发送备份文件'),
const SizedBox(height: 12),
_buildInfoItem('3', '在新设备上选择导入数据,选择备份文件即可恢复'),
_buildInfoItem(colors, '3', '在新设备上选择导入数据,选择备份文件即可恢复'),
const SizedBox(height: 12),
_buildInfoItem('4', '导入数据会完全覆盖当前设备的数据,请谨慎操作'),
_buildInfoItem(colors, '4', '导入数据会完全覆盖当前设备的数据,请谨慎操作'),
],
),
);
}
/// 构建信息项
Widget _buildInfoItem(String number, String text) {
Widget _buildInfoItem(ColorScheme colors, String number, String text) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -274,16 +276,16 @@ class _BackupPageState extends State<BackupPage> {
width: 20,
height: 20,
decoration: BoxDecoration(
color: const Color(0xFFE8E8E8),
color: colors.outline,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
number,
style: const TextStyle(
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w600,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
),
),
),
@@ -292,9 +294,9 @@ class _BackupPageState extends State<BackupPage> {
Expanded(
child: Text(
text,
style: const TextStyle(
style: TextStyle(
fontSize: 13,
color: Color(0xFF666666),
color: colors.onSurface.withValues(alpha: 0.6),
height: 1.5,
),
),
@@ -311,85 +313,93 @@ class _BackupPageState extends State<BackupPage> {
}) {
showDialog(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: Column(
children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.check, color: Color(0xFF1A1A1A), size: 24),
),
const SizedBox(height: 16),
Text(title, style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
],
),
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 12),
Text(
content,
style: const TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.6),
textAlign: TextAlign.center,
),
if (detail != null && detail.isNotEmpty) ...[
const SizedBox(height: 12),
builder: (ctx) {
final colors = Theme.of(ctx).colorScheme;
return AlertDialog(
backgroundColor: colors.surface,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: Column(
children: [
Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
width: 48,
height: 48,
decoration: BoxDecoration(
color: const Color(0xFFF8F8F8),
borderRadius: BorderRadius.circular(8),
),
child: Text(
detail,
style: const TextStyle(fontSize: 11, color: Color(0xFF999999)),
maxLines: 3,
overflow: TextOverflow.ellipsis,
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
),
child: Icon(Icons.check, color: colors.primary, size: 24),
),
const SizedBox(height: 16),
Text(title,
style: TextStyle(
fontSize: 17, fontWeight: FontWeight.w600, color: colors.onSurface)),
],
],
),
contentPadding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
actionsPadding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
style: TextButton.styleFrom(
minimumSize: const Size(120, 40),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('确定', style: TextStyle(fontSize: 14, color: Color(0xFF1A1A1A))),
),
],
),
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 12),
Text(
content,
style: TextStyle(
fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.6),
textAlign: TextAlign.center,
),
if (detail != null && detail.isNotEmpty) ...[
const SizedBox(height: 12),
Container(
width: double.infinity,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(8),
),
child: Text(
detail,
style:
TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.4)),
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
),
],
],
),
contentPadding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
actionsPadding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
style: TextButton.styleFrom(
minimumSize: const Size(120, 40),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: Text('确定', style: TextStyle(fontSize: 14, color: colors.primary)),
),
],
);
},
);
}
/// 导出数据
Future<void> _exportData() async {
setState(() => _isExporting = true);
try {
final result = await BackupService.instance.exportDataWithImages();
if (!mounted) return;
if (result.cancelled) {
ToastUtil.show(context, '已取消导出');
} else if (result.success) {
_showSuccessDialog(
title: '导出成功',
content: '备份文件已保存,包含:\n影视 ${result.movieCount} · 书籍 ${result.bookCount} · 笔记 ${result.noteCount} · 图片 ${result.imageCount}',
content:
'备份文件已保存,包含:\n影视 ${result.movieCount} · 书籍 ${result.bookCount} · 笔记 ${result.noteCount} · 图片 ${result.imageCount}',
detail: result.filePath ?? '',
);
} else {
@@ -411,54 +421,63 @@ class _BackupPageState extends State<BackupPage> {
// 显示确认对话框
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Colors.white,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.08),
borderRadius: BorderRadius.circular(10),
builder: (ctx) {
final colors = Theme.of(ctx).colorScheme;
return AlertDialog(
backgroundColor: colors.surface,
elevation: 0,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
title: Row(
children: [
Container(
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.08),
borderRadius: BorderRadius.circular(10),
),
child: const Icon(Icons.warning_amber_rounded, color: Colors.red, size: 22),
),
child: const Icon(Icons.warning_amber_rounded, color: Colors.red, size: 22),
const SizedBox(width: 12),
Text('确认导入',
style: TextStyle(
fontSize: 17, fontWeight: FontWeight.w600, color: colors.onSurface)),
],
),
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
content: Padding(
padding: const EdgeInsets.only(top: 16),
child: Text(
'导入数据将覆盖当前所有数据,此操作不可恢复。',
style: TextStyle(
fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.6),
),
),
contentPadding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
actionsPadding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: Text('取消',
style: TextStyle(
color: colors.onSurface.withValues(alpha: 0.6), fontSize: 14)),
),
TextButton(
onPressed: () => Navigator.pop(ctx, true),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('确认导入',
style: TextStyle(color: Colors.red, fontSize: 14, fontWeight: FontWeight.w600)),
),
const SizedBox(width: 12),
const Text('确认导入', style: TextStyle(fontSize: 17, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
],
),
titlePadding: const EdgeInsets.fromLTRB(24, 24, 24, 0),
content: const Padding(
padding: EdgeInsets.only(top: 16),
child: Text(
'导入数据将覆盖当前所有数据,此操作不可恢复。',
style: TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.6),
),
),
contentPadding: const EdgeInsets.fromLTRB(24, 0, 24, 0),
actionsPadding: const EdgeInsets.fromLTRB(16, 20, 16, 16),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('取消', style: TextStyle(color: Color(0xFF666666), fontSize: 14)),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
style: TextButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('确认导入', style: TextStyle(color: Colors.red, fontSize: 14, fontWeight: FontWeight.w600)),
),
],
),
);
},
);
if (confirmed != true) return;
@@ -467,7 +486,7 @@ class _BackupPageState extends State<BackupPage> {
try {
final result = await BackupService.instance.importData();
if (!mounted) return;
if (result.cancelled) {
@@ -499,13 +518,13 @@ class _BackupPageState extends State<BackupPage> {
}
/// 构建自动备份区域 - 紧凑一行
Widget _buildAutoBackupSection() {
Widget _buildAutoBackupSection(ColorScheme colors) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: const Color(0xFFFAFAFA),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
border: Border.all(color: colors.outline, width: 0.5),
),
child: Row(
children: [
@@ -513,11 +532,12 @@ class _BackupPageState extends State<BackupPage> {
width: 40,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
color: colors.surface,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFFE8E8E8), width: 0.5),
border: Border.all(color: colors.outline, width: 0.5),
),
child: const Icon(Icons.schedule, size: 20, color: Color(0xFF666666)),
child: Icon(Icons.schedule,
size: 20, color: colors.onSurface.withValues(alpha: 0.6)),
),
const SizedBox(width: 12),
Expanded(
@@ -525,22 +545,25 @@ class _BackupPageState extends State<BackupPage> {
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
Text(
'自动本地备份',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)),
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface),
),
const SizedBox(height: 2),
Text(
_backupDirPath!,
style: const TextStyle(fontSize: 11, color: Color(0xFF999999)),
style:
TextStyle(fontSize: 11, color: colors.onSurface.withValues(alpha: 0.4)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
)
: const Text(
: Text(
'自动本地备份',
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A)),
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface),
),
),
Switch(
@@ -555,14 +578,13 @@ class _BackupPageState extends State<BackupPage> {
}
await _loadAutoBackupStatus();
},
activeColor: const Color(0xFF1A1A1A),
activeTrackColor: const Color(0xFF1A1A1A).withOpacity(0.3),
inactiveThumbColor: Colors.white,
inactiveTrackColor: const Color(0xFFE5E5E5),
activeThumbColor: colors.primary,
activeTrackColor: colors.primary.withValues(alpha: 0.3),
inactiveThumbColor: colors.surface,
inactiveTrackColor: colors.outline,
),
],
),
);
}
}