适配深色模式

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,
),
],
),
);
}
}

View File

@@ -8,95 +8,163 @@ class CloudSyncPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: const Color(0xFFF8F8F8),
backgroundColor: colors.surfaceContainerHigh,
appBar: AppBar(title: const Text('云备份')),
body: ListView(
padding: const EdgeInsets.all(20),
children: [
_buildSectionTitle('选择备份方式'),
_buildSectionTitle(colors, '选择备份方式'),
const SizedBox(height: 12),
_buildOption(
colors: colors,
icon: Icons.storage_outlined,
title: 'WebDAV 备份',
subtitle: '通过 WebDAV 协议备份到个人云盘',
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const WebDAVSyncPage())),
onTap: () =>
Navigator.push(context, MaterialPageRoute(builder: (_) => const WebDAVSyncPage())),
),
const SizedBox(height: 12),
_buildOption(
colors: colors,
icon: Icons.sync_outlined,
title: '服务端实时同步',
subtitle: '自建服务端,多设备数据实时同步',
enabled: false,
onTap: () => Navigator.push(context, MaterialPageRoute(builder: (_) => const ServerSyncPage())),
onTap: () =>
Navigator.push(context, MaterialPageRoute(builder: (_) => const ServerSyncPage())),
),
const SizedBox(height: 28),
_buildInfo(),
_buildInfo(colors),
],
),
);
}
Widget _buildSectionTitle(String title) {
Widget _buildSectionTitle(ColorScheme colors, String title) {
return Row(children: [
Container(width: 3, height: 14, decoration: BoxDecoration(color: const Color(0xFF1A1A1A), borderRadius: BorderRadius.circular(2))),
Container(
width: 3,
height: 14,
decoration:
BoxDecoration(color: colors.primary, borderRadius: BorderRadius.circular(2))),
const SizedBox(width: 8),
Text(title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
Text(title,
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface)),
]);
}
Widget _buildOption({required IconData icon, required String title, required String subtitle, required VoidCallback onTap, bool enabled = true}) {
Widget _buildOption({
required ColorScheme colors,
required IconData icon,
required String title,
required String subtitle,
required VoidCallback onTap,
bool enabled = true,
}) {
return GestureDetector(
onTap: enabled ? onTap : null,
child: Container(
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(
color: enabled ? Colors.white : const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(14),
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 6, offset: const Offset(0, 2))],
color: enabled ? colors.surface : colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.03),
blurRadius: 6,
offset: const Offset(0, 2)),
],
),
child: Row(children: [
Container(width: 44, height: 44, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(10)), child: Icon(icon, color: enabled ? const Color(0xFF666666) : const Color(0xFFBBBBBB), size: 22)),
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(10)),
child: Icon(icon,
color: enabled
? colors.onSurface.withValues(alpha: 0.6)
: colors.onSurface.withValues(alpha: 0.3),
size: 22)),
const SizedBox(width: 14),
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(title, style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: enabled ? const Color(0xFF1A1A1A) : const Color(0xFFBBBBBB))),
Expanded(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text(title,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: enabled ? colors.onSurface : colors.onSurface.withValues(alpha: 0.3))),
const SizedBox(height: 3),
Text(subtitle, style: TextStyle(fontSize: 12, color: enabled ? const Color(0xFF999999) : const Color(0xFFCCCCCC))),
Text(subtitle,
style: TextStyle(
fontSize: 12,
color: enabled
? colors.onSurface.withValues(alpha: 0.4)
: colors.onSurface.withValues(alpha: 0.25))),
])),
Icon(Icons.chevron_right, color: enabled ? const Color(0xFFCCCCCC) : const Color(0xFFE5E5E5)),
Icon(Icons.chevron_right,
color: enabled
? colors.onSurface.withValues(alpha: 0.25)
: colors.outline),
]),
),
);
}
Widget _buildInfo() {
Widget _buildInfo(ColorScheme colors) {
return Container(
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(14),
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 6, offset: const Offset(0, 2))],
decoration: BoxDecoration(
color: colors.surface,
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.03),
blurRadius: 6,
offset: const Offset(0, 2)),
],
),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(children: [
Container(width: 36, height: 36, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(8)), child: const Icon(Icons.info_outline, size: 18, color: Color(0xFF666666))),
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(8)),
child: Icon(Icons.info_outline,
size: 18, color: colors.onSurface.withValues(alpha: 0.6))),
const SizedBox(width: 10),
const Text('使用说明', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
Text('使用说明',
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface)),
]),
const SizedBox(height: 14),
_infoItem('WebDAV 备份:将数据备份到支持 WebDAV 的云盘'),
_infoItem(colors, 'WebDAV 备份:将数据备份到支持 WebDAV 的云盘'),
const SizedBox(height: 8),
_infoItem('服务端实时同步:通过自建服务端实现多设备实时同步'),
_infoItem(colors, '服务端实时同步:通过自建服务端实现多设备实时同步'),
const SizedBox(height: 8),
_infoItem('激活码由服务端管理员在管理后台生成'),
_infoItem(colors, '激活码由服务端管理员在管理后台生成'),
const SizedBox(height: 8),
_infoItem('建议定期备份 + 实时同步配合使用'),
_infoItem(colors, '建议定期备份 + 实时同步配合使用'),
]),
);
}
Widget _infoItem(String text) {
Widget _infoItem(ColorScheme colors, String text) {
return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Container(width: 5, height: 5, margin: const EdgeInsets.only(top: 5), decoration: BoxDecoration(color: const Color(0xFFBBBBBB), shape: BoxShape.circle)),
Container(
width: 5,
height: 5,
margin: const EdgeInsets.only(top: 5),
decoration: BoxDecoration(
color: colors.onSurface.withValues(alpha: 0.3), shape: BoxShape.circle)),
const SizedBox(width: 10),
Expanded(child: Text(text, style: const TextStyle(fontSize: 12, color: Color(0xFF888888), height: 1.5))),
Expanded(
child: Text(text,
style: TextStyle(
fontSize: 12, color: colors.onSurface.withValues(alpha: 0.5), height: 1.5))),
]);
}
}

View File

@@ -157,16 +157,24 @@ class _ServerSyncPageState extends State<ServerSyncPage> {
Future<void> _disconnect() async {
final confirm = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: const Text('断开连接', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
content: const Text('将清除服务器配置和激活信息,确定要断开吗?', style: TextStyle(fontSize: 14, color: Color(0xFF666666))),
actions: [
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消', style: TextStyle(color: Color(0xFF999999)))),
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('确定', style: TextStyle(color: Color(0xFFE53935)))),
],
),
builder: (ctx) {
final colors = Theme.of(ctx).colorScheme;
return AlertDialog(
backgroundColor: colors.surface,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
title: const Text('断开连接', style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600)),
content: Text('将清除服务器配置和激活信息,确定要断开吗?',
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6))),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx, false),
child: Text('取消', style: TextStyle(color: colors.onSurface.withValues(alpha: 0.4)))),
TextButton(
onPressed: () => Navigator.pop(ctx, true),
child: const Text('确定', style: TextStyle(color: Color(0xFFE53935)))),
],
);
},
);
if (confirm != true) return;
@@ -190,63 +198,107 @@ class _ServerSyncPageState extends State<ServerSyncPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: const Color(0xFFF8F8F8),
backgroundColor: colors.surfaceContainerHigh,
appBar: AppBar(title: const Text('服务端实时同步')),
body: ListView(padding: const EdgeInsets.all(20), children: [
// 状态卡片
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16),
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 8, offset: const Offset(0, 2))],
decoration: BoxDecoration(
color: colors.surface,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 8, offset: const Offset(0, 2))
],
),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(children: [
Container(width: 10, height: 10, decoration: BoxDecoration(
color: _isActivated ? const Color(0xFF66BB6A) : const Color(0xFFDDDDDD), shape: BoxShape.circle)),
Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: _isActivated
? const Color(0xFF66BB6A)
: colors.onSurface.withValues(alpha: 0.15),
shape: BoxShape.circle)),
const SizedBox(width: 10),
Text(_isActivated ? '已激活' : '未激活',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600,
color: _isActivated ? const Color(0xFF66BB6A) : const Color(0xFFBBBBBB))),
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: _isActivated
? const Color(0xFF66BB6A)
: colors.onSurface.withValues(alpha: 0.3))),
const Spacer(),
if (_isActivated)
GestureDetector(
onTap: _disconnect,
child: Container(padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(6)),
child: const Text('断开', style: TextStyle(fontSize: 12, color: Color(0xFFE57373)))),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
decoration: BoxDecoration(
color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(6)),
child: const Text('断开',
style: TextStyle(fontSize: 12, color: Color(0xFFE57373)))),
),
]),
const SizedBox(height: 20),
const Text('服务器地址', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
Text('服务器地址',
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
const SizedBox(height: 6),
TextField(controller: _urlController, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
decoration: _inputDeco('例: http://192.168.1.100:5000')),
TextField(
controller: _urlController,
style: TextStyle(fontSize: 14, color: colors.onSurface),
decoration: _inputDeco(colors, '例: http://192.168.1.100:5000'),
),
const SizedBox(height: 14),
const Text('激活码', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
Text('激活码',
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
const SizedBox(height: 6),
TextField(controller: _codeController, style: const TextStyle(fontSize: 14, color: Color(0xFF1A1A1A)),
textCapitalization: TextCapitalization.characters, decoration: _inputDeco('例: MK-A1B2C3D4E5F6')),
TextField(
controller: _codeController,
style: TextStyle(fontSize: 14, color: colors.onSurface),
textCapitalization: TextCapitalization.characters,
decoration: _inputDeco(colors, '例: MK-A1B2C3D4E5F6')),
const SizedBox(height: 16),
SizedBox(width: double.infinity,
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _isChecking ? null : _checkActivation,
style: ElevatedButton.styleFrom(backgroundColor: const Color(0xFF1A1A1A), foregroundColor: Colors.white,
disabledBackgroundColor: const Color(0xFFDDDDDD), elevation: 0,
style: ElevatedButton.styleFrom(
backgroundColor: colors.primary,
foregroundColor: colors.onPrimary,
disabledBackgroundColor: colors.onSurface.withValues(alpha: 0.15),
elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
padding: const EdgeInsets.symmetric(vertical: 13)),
child: _isChecking
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
: Text(_isActivated ? '重新验证' : '验证激活', style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
? SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2, color: colors.onPrimary))
: Text(_isActivated ? '重新验证' : '验证激活',
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
),
),
if (_expiresText.isNotEmpty) ...[
const SizedBox(height: 12),
Center(child: Row(mainAxisSize: MainAxisSize.min, children: [
Icon(Icons.access_time, size: 14, color: _prefs.syncIsPermanent ? const Color(0xFF66BB6A) : const Color(0xFFFF9800)),
Center(
child: Row(mainAxisSize: MainAxisSize.min, children: [
Icon(Icons.access_time,
size: 14,
color: _prefs.syncIsPermanent
? const Color(0xFF66BB6A)
: const Color(0xFFFF9800)),
const SizedBox(width: 6),
Text(_expiresText, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500,
color: _prefs.syncIsPermanent ? const Color(0xFF66BB6A) : const Color(0xFFFF9800))),
Text(_expiresText,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: _prefs.syncIsPermanent
? const Color(0xFF66BB6A)
: const Color(0xFFFF9800))),
])),
],
]),
@@ -255,47 +307,78 @@ class _ServerSyncPageState extends State<ServerSyncPage> {
// 同步开关
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(16),
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 8, offset: const Offset(0, 2))]),
decoration: BoxDecoration(
color: colors.surface,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.03), blurRadius: 8, offset: const Offset(0, 2))
]),
child: Row(children: [
Container(width: 44, height: 44, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(10)),
child: Icon(_syncEnabled ? Icons.sync : Icons.sync_disabled,
color: _syncEnabled ? const Color(0xFF1A1A1A) : const Color(0xFFCCCCCC), size: 22)),
Container(
width: 44,
height: 44,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(10)),
child: Icon(_syncEnabled ? Icons.sync : Icons.sync_disabled,
color: _syncEnabled
? colors.primary
: colors.onSurface.withValues(alpha: 0.25),
size: 22)),
const SizedBox(width: 14),
Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
const Text('服务端实时同步', style: TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: Color(0xFF1A1A1A))),
Expanded(
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Text('服务端实时同步',
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.w500, color: colors.onSurface)),
const SizedBox(height: 2),
Text(_syncEnabled ? '使用服务端数据,多设备实时共享' : '关闭后下载数据到本地使用',
style: const TextStyle(fontSize: 12, color: Color(0xFFBBBBBB))),
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.3))),
])),
Switch(value: _syncEnabled, onChanged: _isActivated ? _toggleSync : null,
activeColor: const Color(0xFF1A1A1A), activeTrackColor: const Color(0xFF1A1A1A).withOpacity(0.3),
inactiveThumbColor: Colors.white, inactiveTrackColor: const Color(0xFFE5E5E5)),
Switch(
value: _syncEnabled,
onChanged: _isActivated ? _toggleSync : null,
activeThumbColor: colors.primary,
activeTrackColor: colors.primary.withValues(alpha: 0.3),
inactiveThumbColor: colors.surface,
inactiveTrackColor: colors.outline),
]),
),
const SizedBox(height: 24),
// 说明
Container(
padding: const EdgeInsets.all(18),
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(14),
boxShadow: [BoxShadow(color: Colors.black.withValues(alpha: 0.03), blurRadius: 6, offset: const Offset(0, 2))]),
decoration: BoxDecoration(
color: colors.surface,
borderRadius: BorderRadius.circular(14),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.03), blurRadius: 6, offset: const Offset(0, 2))
]),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
Row(children: [
Container(width: 36, height: 36, decoration: BoxDecoration(color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(8)),
child: const Icon(Icons.info_outline, size: 18, color: Color(0xFF666666))),
Container(
width: 36,
height: 36,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest, borderRadius: BorderRadius.circular(8)),
child: Icon(Icons.info_outline,
size: 18, color: colors.onSurface.withValues(alpha: 0.6))),
const SizedBox(width: 10),
const Text('使用说明', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
Text('使用说明',
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w600, color: colors.onSurface)),
]),
const SizedBox(height: 14),
_infoItem('1. 在服务端管理后台生成激活码'),
_infoItem(colors, '1. 在服务端管理后台生成激活码'),
const SizedBox(height: 8),
_infoItem('2. 输入服务器地址和激活码完成验证'),
_infoItem(colors, '2. 输入服务器地址和激活码完成验证'),
const SizedBox(height: 8),
_infoItem('3. 验证通过后自动开启实时同步'),
_infoItem(colors, '3. 验证通过后自动开启实时同步'),
const SizedBox(height: 8),
_infoItem('4. 开启时所有数据通过服务端接口操作'),
_infoItem(colors, '4. 开启时所有数据通过服务端接口操作'),
const SizedBox(height: 8),
_infoItem('5. 关闭时从服务端下载数据到本地使用'),
_infoItem(colors, '5. 关闭时从服务端下载数据到本地使用'),
]),
),
const SizedBox(height: 40),
@@ -303,21 +386,33 @@ class _ServerSyncPageState extends State<ServerSyncPage> {
);
}
InputDecoration _inputDeco(String hint) {
InputDecoration _inputDeco(ColorScheme colors, String hint) {
return InputDecoration(
hintText: hint, hintStyle: const TextStyle(fontSize: 13, color: Color(0xFFCCCCCC)),
filled: true, fillColor: const Color(0xFFF8F8F8),
hintText: hint,
hintStyle: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.25)),
filled: true,
fillColor: colors.surfaceContainerHigh,
contentPadding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: BorderSide.none),
focusedBorder: OutlineInputBorder(borderRadius: BorderRadius.circular(10), borderSide: const BorderSide(color: Color(0xFF1A1A1A), width: 1)),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(color: colors.primary, width: 1)),
);
}
Widget _infoItem(String text) {
Widget _infoItem(ColorScheme colors, String text) {
return Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Container(width: 5, height: 5, margin: const EdgeInsets.only(top: 6), decoration: BoxDecoration(color: const Color(0xFFBBBBBB), shape: BoxShape.circle)),
Container(
width: 5,
height: 5,
margin: const EdgeInsets.only(top: 6),
decoration: BoxDecoration(
color: colors.onSurface.withValues(alpha: 0.3), shape: BoxShape.circle)),
const SizedBox(width: 10),
Expanded(child: Text(text, style: const TextStyle(fontSize: 13, color: Color(0xFF888888), height: 1.5))),
Expanded(
child: Text(text,
style: TextStyle(
fontSize: 13, color: colors.onSurface.withValues(alpha: 0.5), height: 1.5))),
]);
}
}

View File

@@ -66,22 +66,37 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
final password = _passwordController.text;
final path = _pathController.text.trim();
if (url.isEmpty) { ToastUtil.show(context, '请输入服务器地址'); return; }
if (username.isEmpty) { ToastUtil.show(context, '请输入用户名'); return; }
if (password.isEmpty) { ToastUtil.show(context, '请输入密码'); return; }
if (url.isEmpty) {
ToastUtil.show(context, '请输入服务器地址');
return;
}
if (username.isEmpty) {
ToastUtil.show(context, '请输入用户名');
return;
}
if (password.isEmpty) {
ToastUtil.show(context, '请输入密码');
return;
}
setState(() => _isLoading = true);
try {
final result = await WebDAVService.instance.testConnection(
url: url, username: username, password: password, path: path,
url: url,
username: username,
password: password,
path: path,
);
if (!mounted) return;
if (result['success'] == true) {
await WebDAVService.instance.saveConfig(
url: url, username: username, password: password, path: path,
url: url,
username: username,
password: password,
path: path,
);
setState(() => _isConfigured = true);
ToastUtil.show(context, result['message'] ?? '连接成功,配置已保存');
@@ -104,7 +119,7 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
if (result.success) {
final details = '上传: ${result.uploadedFiles} 文件, ${result.uploadedImages} 图片\n'
'下载: ${result.downloadedFiles} 文件, ${result.downloadedImages} 图片';
'下载: ${result.downloadedFiles} 文件, ${result.downloadedImages} 图片';
if (result.needReload) {
ToastUtil.show(context, '数据已更新,正在重新加载...');
@@ -129,39 +144,48 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
void _showResultDialog(String title, String content) {
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),
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: 48,
height: 48,
decoration: BoxDecoration(
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(12),
),
child: Icon(Icons.check, color: colors.primary, size: 24),
),
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: Padding(
padding: const EdgeInsets.only(top: 12),
child: Text(content, style: const TextStyle(fontSize: 14, color: Color(0xFF666666), height: 1.6), textAlign: TextAlign.center),
),
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))),
const SizedBox(height: 16),
Text(title,
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: 12),
child: Text(content,
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6), height: 1.6),
textAlign: TextAlign.center),
),
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)),
),
],
);
},
);
}
@@ -188,25 +212,40 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
final selected = await showModalBottomSheet<int>(
context: context,
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
builder: (ctx) => SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 8),
Container(width: 36, height: 4, decoration: BoxDecoration(color: const Color(0xFFDDDDDD), borderRadius: BorderRadius.circular(2))),
const SizedBox(height: 12),
const Text('同步间隔', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xFF1A1A1A))),
const SizedBox(height: 8),
...intervals.map((i) => ListTile(
title: Text('$i 分钟', style: TextStyle(fontSize: 15, fontWeight: _autoSyncInterval == i ? FontWeight.w600 : FontWeight.w400, color: const Color(0xFF1A1A1A))),
trailing: _autoSyncInterval == i ? const Icon(Icons.check, color: Color(0xFF1A1A1A), size: 20) : null,
onTap: () => Navigator.pop(ctx, i),
)),
const SizedBox(height: 8),
],
),
),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
builder: (ctx) {
final colors = Theme.of(ctx).colorScheme;
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const SizedBox(height: 8),
Container(
width: 36,
height: 4,
decoration: BoxDecoration(
color: colors.onSurface.withValues(alpha: 0.15), borderRadius: BorderRadius.circular(2))),
const SizedBox(height: 12),
Text('同步间隔',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: colors.onSurface)),
const SizedBox(height: 8),
...intervals.map((i) => ListTile(
title: Text('$i 分钟',
style: TextStyle(
fontSize: 15,
fontWeight: _autoSyncInterval == i ? FontWeight.w600 : FontWeight.w400,
color: colors.onSurface)),
trailing: _autoSyncInterval == i
? Icon(Icons.check, color: colors.primary, size: 20)
: null,
onTap: () => Navigator.pop(ctx, i),
)),
const SizedBox(height: 8),
],
),
);
},
);
if (selected != null && selected != _autoSyncInterval) {
@@ -226,41 +265,54 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
Future<void> _clearConfig() async {
final confirmed = await showDialog<bool>(
context: context,
builder: (ctx) => 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)),
child: const Icon(Icons.warning_amber_rounded, color: Colors.red, size: 22),
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),
),
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('确定要清除 WebDAV 配置吗?',
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('确定要清除 WebDAV 配置吗?', 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(ctx, 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(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)),
),
],
),
);
},
);
if (confirmed == true) {
@@ -281,46 +333,54 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: Colors.white,
backgroundColor: colors.surface,
appBar: AppBar(title: const Text('WebDAV 备份')),
body: _isLoading && !_isConfigured
? const Center(child: CircularProgressIndicator(strokeWidth: 2, color: Color(0xFF1A1A1A)))
? Center(child: CircularProgressIndicator(strokeWidth: 2, color: colors.primary))
: ListView(
padding: const EdgeInsets.symmetric(horizontal: 24),
children: [
const SizedBox(height: 8),
// 已连接提示
if (_isConfigured) _buildConnectedBanner(),
if (_isConfigured) _buildConnectedBanner(colors),
// 服务器配置
_buildSectionLabel('服务器配置'),
_buildSectionLabel(colors, '服务器配置'),
const SizedBox(height: 16),
_buildInput(
colors: colors,
controller: _urlController,
hint: '服务器地址,如 https://dav.example.com',
icon: Icons.link,
),
const SizedBox(height: 12),
_buildInput(
colors: colors,
controller: _usernameController,
hint: '用户名',
icon: Icons.person_outline,
),
const SizedBox(height: 12),
_buildInput(
colors: colors,
controller: _passwordController,
hint: '密码',
icon: Icons.lock_outline,
obscure: _obscurePassword,
suffix: GestureDetector(
onTap: () => setState(() => _obscurePassword = !_obscurePassword),
child: Icon(_obscurePassword ? Icons.visibility_off : Icons.visibility, size: 20, color: const Color(0xFFBBBBBB)),
child: Icon(
_obscurePassword ? Icons.visibility_off : Icons.visibility,
size: 20,
color: colors.onSurface.withValues(alpha: 0.3)),
),
),
const SizedBox(height: 12),
_buildInput(
colors: colors,
controller: _pathController,
hint: '同步路径,如 /mooknote',
icon: Icons.folder_outlined,
@@ -328,14 +388,15 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
const SizedBox(height: 24),
// 测试并保存
_buildBtn('测试并保存', onTap: _isLoading ? null : _saveConfig),
_buildBtn(colors, '测试并保存', onTap: _isLoading ? null : _saveConfig),
const SizedBox(height: 40),
if (_isConfigured) ...[
// 自动同步
_buildSectionLabel('自动同步'),
_buildSectionLabel(colors, '自动同步'),
const SizedBox(height: 12),
_buildSwitchRow(
colors: colors,
icon: Icons.sync,
label: '自动同步',
sub: _isAutoSyncEnabled ? '$_autoSyncInterval 分钟自动同步' : '关闭',
@@ -345,6 +406,7 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
if (_isAutoSyncEnabled) ...[
const SizedBox(height: 4),
_buildTappableRow(
colors: colors,
label: '同步间隔',
value: '$_autoSyncInterval 分钟',
onTap: _isLoading ? null : _showIntervalPicker,
@@ -354,27 +416,31 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
const SizedBox(height: 32),
// 手动同步
_buildSectionLabel('手动同步'),
_buildSectionLabel(colors, '手动同步'),
const SizedBox(height: 16),
Row(
children: [
Expanded(child: _buildDirectionChip('上传到云端', SyncDirection.upload, Icons.upload)),
Expanded(
child: _buildDirectionChip(
colors, '上传到云端', SyncDirection.upload, Icons.upload)),
const SizedBox(width: 12),
Expanded(child: _buildDirectionChip('下载到本地', SyncDirection.download, Icons.download)),
Expanded(
child: _buildDirectionChip(
colors, '下载到本地', SyncDirection.download, Icons.download)),
],
),
const SizedBox(height: 20),
_buildBtn('立即同步', onTap: _isLoading ? null : _syncData, loading: _isLoading),
_buildBtn(colors, '立即同步', onTap: _isLoading ? null : _syncData, loading: _isLoading),
const SizedBox(height: 32),
// 清除配置
_buildTextBtn('清除配置', onTap: _isLoading ? null : _clearConfig),
_buildTextBtn(colors, '清除配置', onTap: _isLoading ? null : _clearConfig),
const SizedBox(height: 8),
],
const SizedBox(height: 32),
_buildTips(),
_buildTips(colors),
const SizedBox(height: 60),
],
),
@@ -383,40 +449,48 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
// ── widgets ─────────────────────────────────────────
Widget _buildConnectedBanner() {
Widget _buildConnectedBanner(ColorScheme colors) {
return Container(
margin: const EdgeInsets.only(bottom: 24),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: const Color(0xFFF5F5F5),
color: colors.surfaceContainerHighest,
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Container(
width: 6, height: 6,
width: 6,
height: 6,
decoration: const BoxDecoration(color: Color(0xFF4CAF50), shape: BoxShape.circle),
),
const SizedBox(width: 10),
Expanded(
child: Text(
_urlController.text,
style: const TextStyle(fontSize: 13, color: Color(0xFF666666)),
style: TextStyle(fontSize: 13, color: colors.onSurface.withValues(alpha: 0.6)),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
const Text('已连接', style: TextStyle(fontSize: 12, color: Color(0xFF999999))),
Text('已连接',
style: TextStyle(fontSize: 12, color: colors.onSurface.withValues(alpha: 0.4))),
],
),
);
}
Widget _buildSectionLabel(String text) {
return Text(text, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: Color(0xFF999999), letterSpacing: 0.5));
Widget _buildSectionLabel(ColorScheme colors, String text) {
return Text(text,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: colors.onSurface.withValues(alpha: 0.4),
letterSpacing: 0.5));
}
Widget _buildInput({
required ColorScheme colors,
required TextEditingController controller,
required String hint,
required IconData icon,
@@ -426,35 +500,37 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
return TextField(
controller: controller,
obscureText: obscure,
style: const TextStyle(fontSize: 15, color: Color(0xFF1A1A1A)),
style: TextStyle(fontSize: 15, color: colors.onSurface),
decoration: InputDecoration(
hintText: hint,
hintStyle: const TextStyle(fontSize: 15, color: Color(0xFFBBBBBB)),
hintStyle: TextStyle(fontSize: 15, color: colors.onSurface.withValues(alpha: 0.3)),
prefixIcon: Padding(
padding: const EdgeInsets.only(left: 4, right: 8),
child: Icon(icon, size: 20, color: const Color(0xFFBBBBBB)),
child: Icon(icon, size: 20, color: colors.onSurface.withValues(alpha: 0.3)),
),
prefixIconConstraints: const BoxConstraints(minWidth: 44),
suffixIcon: suffix != null ? Padding(
padding: const EdgeInsets.only(right: 8),
child: suffix,
) : null,
suffixIcon: suffix != null
? Padding(
padding: const EdgeInsets.only(right: 8),
child: suffix,
)
: null,
filled: true,
fillColor: const Color(0xFFF8F8F8),
fillColor: colors.surfaceContainerHigh,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide.none,
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(color: Color(0xFF1A1A1A), width: 1),
borderSide: BorderSide(color: colors.primary, width: 1),
),
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 15),
),
);
}
Widget _buildBtn(String text, {VoidCallback? onTap, bool loading = false}) {
Widget _buildBtn(ColorScheme colors, String text, {VoidCallback? onTap, bool loading = false}) {
final disabled = onTap == null;
return GestureDetector(
onTap: onTap,
@@ -462,30 +538,44 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 15),
decoration: BoxDecoration(
color: disabled ? const Color(0xFFDDDDDD) : const Color(0xFF1A1A1A),
color: disabled ? colors.onSurface.withValues(alpha: 0.15) : colors.primary,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: loading
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.white)))
: Text(text, style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600, color: Colors.white)),
? SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2, valueColor: AlwaysStoppedAnimation(colors.onPrimary)))
: Text(text,
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.w600, color: colors.onPrimary)),
),
),
);
}
Widget _buildTextBtn(String text, {VoidCallback? onTap}) {
Widget _buildTextBtn(ColorScheme colors, String text, {VoidCallback? onTap}) {
return GestureDetector(
onTap: onTap,
child: Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Text(text, style: TextStyle(fontSize: 14, color: onTap == null ? const Color(0xFFCCCCCC) : const Color(0xFF999999)))),
child: Text(
text,
style: TextStyle(
fontSize: 14,
color: onTap == null
? colors.onSurface.withValues(alpha: 0.25)
: colors.onSurface.withValues(alpha: 0.4))),
),
),
);
}
Widget _buildSwitchRow({
required ColorScheme colors,
required IconData icon,
required String label,
required String sub,
@@ -495,26 +585,30 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: const Color(0xFFF8F8F8),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
Icon(icon, size: 20, color: value ? const Color(0xFF1A1A1A) : const Color(0xFFBBBBBB)),
Icon(icon,
size: 20,
color: value ? colors.primary : colors.onSurface.withValues(alpha: 0.3)),
const SizedBox(width: 12),
Expanded(
child: Text(
value ? sub : label,
style: TextStyle(fontSize: 14, color: value ? const Color(0xFF666666) : const Color(0xFF1A1A1A)),
style: TextStyle(
fontSize: 14,
color: value ? colors.onSurface.withValues(alpha: 0.6) : colors.onSurface),
),
),
Switch(
value: value,
onChanged: onChanged,
activeColor: const Color(0xFF1A1A1A),
activeTrackColor: const Color(0xFF1A1A1A).withOpacity(0.3),
inactiveThumbColor: Colors.white,
inactiveTrackColor: const Color(0xFFDDDDDD),
activeThumbColor: colors.primary,
activeTrackColor: colors.primary.withValues(alpha: 0.3),
inactiveThumbColor: colors.surface,
inactiveTrackColor: colors.onSurface.withValues(alpha: 0.15),
),
],
),
@@ -522,6 +616,7 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
}
Widget _buildTappableRow({
required ColorScheme colors,
required String label,
required String value,
VoidCallback? onTap,
@@ -531,77 +626,99 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: const Color(0xFFF8F8F8),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
const SizedBox(width: 32),
Text(label, style: const TextStyle(fontSize: 14, color: Color(0xFF999999))),
Text(label,
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.4))),
const Spacer(),
Text(value, style: const TextStyle(fontSize: 14, color: Color(0xFF666666))),
Text(value,
style: TextStyle(fontSize: 14, color: colors.onSurface.withValues(alpha: 0.6))),
const SizedBox(width: 4),
const Icon(Icons.chevron_right, size: 16, color: Color(0xFFCCCCCC)),
Icon(Icons.chevron_right,
size: 16, color: colors.onSurface.withValues(alpha: 0.25)),
],
),
),
);
}
Widget _buildDirectionChip(String label, SyncDirection dir, IconData icon) {
Widget _buildDirectionChip(ColorScheme colors, String label, SyncDirection dir, IconData icon) {
final selected = _syncDirection == dir;
return GestureDetector(
onTap: () => setState(() => _syncDirection = dir),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 14),
decoration: BoxDecoration(
color: selected ? const Color(0xFF1A1A1A) : const Color(0xFFF8F8F8),
color: selected ? colors.primary : colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(10),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(icon, size: 16, color: selected ? Colors.white : const Color(0xFF999999)),
Icon(icon,
size: 16,
color: selected
? colors.onPrimary
: colors.onSurface.withValues(alpha: 0.4)),
const SizedBox(width: 6),
Text(label, style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500, color: selected ? Colors.white : const Color(0xFF666666))),
Text(label,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: selected
? colors.onPrimary
: colors.onSurface.withValues(alpha: 0.6))),
],
),
),
);
}
Widget _buildTips() {
Widget _buildTips(ColorScheme colors) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFFF8F8F8),
color: colors.surfaceContainerHigh,
borderRadius: BorderRadius.circular(10),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('支持的服务', style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xFF999999), letterSpacing: 0.5)),
Text('支持的服务',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: colors.onSurface.withValues(alpha: 0.4),
letterSpacing: 0.5)),
const SizedBox(height: 10),
_tip('坚果云、Nextcloud、AList 等 WebDAV 服务'),
_tip('服务器地址需包含 https://'),
_tip('首次同步可能需要较长时间'),
_tip(colors, '坚果云、Nextcloud、AList 等 WebDAV 服务'),
_tip(colors, '服务器地址需包含 https://'),
_tip(colors, '首次同步可能需要较长时间'),
],
),
);
}
Widget _tip(String text) {
Widget _tip(ColorScheme colors, String text) {
return Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(top: 8),
child: Icon(Icons.circle, size: 4, color: Color(0xFFCCCCCC)),
Padding(
padding: const EdgeInsets.only(top: 8),
child: Icon(Icons.circle,
size: 4, color: colors.onSurface.withValues(alpha: 0.25)),
),
const SizedBox(width: 8),
Expanded(child: Text(text, style: const TextStyle(fontSize: 13, color: Color(0xFF888888), height: 1.5))),
Expanded(
child: Text(text,
style: TextStyle(
fontSize: 13, color: colors.onSurface.withValues(alpha: 0.5), height: 1.5))),
],
),
);