From 75f735282fd3a26d92d47795efd113c690c065ed Mon Sep 17 00:00:00 2001 From: DelLevin-Home Date: Tue, 7 Jul 2026 01:37:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=87=E4=BB=BD=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/pages/home/main_content_page.dart | 47 +++++++++++++++------------ lib/pages/sync/webdav_sync_page.dart | 24 +++++++++----- pubspec.yaml | 2 +- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/lib/pages/home/main_content_page.dart b/lib/pages/home/main_content_page.dart index 989cbca..3fa67d9 100644 --- a/lib/pages/home/main_content_page.dart +++ b/lib/pages/home/main_content_page.dart @@ -420,14 +420,17 @@ class _CloudSheetContentState extends State<_CloudSheetContent> { } Future _performSync(SyncDirection direction) async { + // 保存外层 navigator,pop 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? details}) { - final colors = Theme.of(context).colorScheme; + void _showResultDialog(NavigatorState navigator, {required String title, required String message, required bool isSuccess, Map? details}) { + // 使用保存的 navigator context,而非 state context(bottom 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)), diff --git a/lib/pages/sync/webdav_sync_page.dart b/lib/pages/sync/webdav_sync_page.dart index dba1d3e..8f9ad86 100644 --- a/lib/pages/sync/webdav_sync_page.dart +++ b/lib/pages/sync/webdav_sync_page.dart @@ -374,9 +374,14 @@ class _WebDAVSyncPageState extends State { @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 { // 已连接提示 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 { ], 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 { ), ], ), + ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index 0ae71b9..964efd5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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