优化备份逻辑

This commit is contained in:
DelLevin-Home
2026-07-07 01:37:11 +08:00
parent 669a4af329
commit 75f735282f
3 changed files with 42 additions and 31 deletions

View File

@@ -420,14 +420,17 @@ class _CloudSheetContentState extends State<_CloudSheetContent> {
}
Future<void> _performSync(SyncDirection direction) async {
// 保存外层 navigatorpop bottom sheet 后还能用它弹 dialog
final navigator = Navigator.of(context);
if (direction == SyncDirection.upload) {
// 上传:先打包,再上传
setState(() => _syncStep = '正在打包数据...');
final exportResult = await WebDAVService.instance.exportLocalData();
if (!exportResult.success || exportResult.zipPath == null) {
if (mounted) {
setState(() => _syncing = false);
_showResultDialog(title: '同步失败', message: exportResult.errorMessage ?? '创建备份失败', isSuccess: false);
Navigator.pop(context); // 关闭 bottom sheet
_showResultDialog(navigator, title: '同步失败', message: exportResult.errorMessage ?? '创建备份失败', isSuccess: false);
}
return;
}
@@ -443,22 +446,22 @@ class _CloudSheetContentState extends State<_CloudSheetContent> {
}
if (mounted) {
setState(() => _syncing = false);
Navigator.pop(context);
_showResultDialog(
title: result.success ? '同步成功' : '同步失败',
message: result.message.isNotEmpty ? result.message : (result.success ? '同步成功' : '同步失败'),
isSuccess: result.success,
details: {'uploaded': result.uploadedFiles + result.uploadedImages, 'downloaded': result.downloadedFiles + result.downloadedImages},
);
Navigator.pop(context); // 关闭 bottom sheet
}
_showResultDialog(navigator,
title: result.success ? '同步成功' : '同步失败',
message: result.message.isNotEmpty ? result.message : (result.success ? '同步成功' : '同步失败'),
isSuccess: result.success,
details: {'uploaded': result.uploadedFiles + result.uploadedImages, 'downloaded': result.downloadedFiles + result.downloadedImages},
);
} else {
// 下载
setState(() => _syncStep = '正在从云端下载...');
final config = await WebDAVService.instance.getConfig();
if (config == null) {
if (mounted) {
setState(() => _syncing = false);
_showResultDialog(title: '同步失败', message: '请先配置 WebDAV 服务器', isSuccess: false);
Navigator.pop(context);
_showResultDialog(navigator, title: '同步失败', message: '请先配置 WebDAV 服务器', isSuccess: false);
}
return;
}
@@ -472,14 +475,14 @@ class _CloudSheetContentState extends State<_CloudSheetContent> {
}
if (mounted) {
setState(() => _syncing = false);
Navigator.pop(context);
_showResultDialog(
title: result.success ? '同步成功' : '同步失败',
message: result.message.isNotEmpty ? result.message : (result.success ? '同步成功' : '同步失败'),
isSuccess: result.success,
details: {'uploaded': result.uploadedFiles + result.uploadedImages, 'downloaded': result.downloadedFiles + result.downloadedImages},
);
Navigator.pop(context); // 关闭 bottom sheet
}
_showResultDialog(navigator,
title: result.success ? '同步成功' : '同步失败',
message: result.message.isNotEmpty ? result.message : (result.success ? '同步成功' : '同步失败'),
isSuccess: result.success,
details: {'uploaded': result.uploadedFiles + result.uploadedImages, 'downloaded': result.downloadedFiles + result.downloadedImages},
);
}
}
@@ -597,10 +600,12 @@ class _CloudSheetContentState extends State<_CloudSheetContent> {
);
}
void _showResultDialog({required String title, required String message, required bool isSuccess, Map<String, dynamic>? details}) {
final colors = Theme.of(context).colorScheme;
void _showResultDialog(NavigatorState navigator, {required String title, required String message, required bool isSuccess, Map<String, dynamic>? details}) {
// 使用保存的 navigator context而非 state contextbottom sheet 已 pop
final overlayCtx = navigator.context;
final colors = Theme.of(overlayCtx).colorScheme;
showDialog(
context: context,
context: overlayCtx,
builder: (dialogCtx) => AlertDialog(
backgroundColor: colors.surface, elevation: 0,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),

View File

@@ -374,9 +374,14 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return Scaffold(
backgroundColor: colors.surface,
appBar: AppBar(title: const Text('WebDAV 备份')),
return PopScope(
canPop: !_isLoading,
child: Scaffold(
backgroundColor: colors.surface,
appBar: AppBar(
title: const Text('WebDAV 备份'),
leading: _isLoading ? const SizedBox.shrink() : null,
),
body: Stack(
children: [
ListView(
@@ -387,6 +392,12 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
// 已连接提示
if (_isConfigured) _buildConnectedBanner(colors),
if (_isConfigured) ...[
// 远程备份信息卡片(包含操作按钮)
_buildRemoteInfoCard(colors),
const SizedBox(height: 24),
],
// 服务器配置
_buildSectionLabel(colors, '服务器配置'),
const SizedBox(height: 12),
@@ -444,12 +455,6 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
],
const SizedBox(height: 28),
if (_isConfigured) ...[
// 远程备份信息卡片(包含操作按钮)
_buildRemoteInfoCard(colors),
const SizedBox(height: 24),
],
const SizedBox(height: 24),
_buildTips(colors),
const SizedBox(height: 40),
@@ -457,6 +462,7 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
),
],
),
),
);
}

View File

@@ -1,7 +1,7 @@
name: mooknote
description: "app for tracking movies, books, and notes"
publish_to: 'none'
version: 0.2.4
version: 0.2.5
environment:
sdk: ^3.5.0