generated from dellevin/template
优化备份逻辑
This commit is contained in:
@@ -420,14 +420,17 @@ class _CloudSheetContentState extends State<_CloudSheetContent> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _performSync(SyncDirection direction) async {
|
Future<void> _performSync(SyncDirection direction) async {
|
||||||
|
// 保存外层 navigator,pop bottom sheet 后还能用它弹 dialog
|
||||||
|
final navigator = Navigator.of(context);
|
||||||
|
|
||||||
if (direction == SyncDirection.upload) {
|
if (direction == SyncDirection.upload) {
|
||||||
// 上传:先打包,再上传
|
// 上传:先打包,再上传
|
||||||
setState(() => _syncStep = '正在打包数据...');
|
setState(() => _syncStep = '正在打包数据...');
|
||||||
final exportResult = await WebDAVService.instance.exportLocalData();
|
final exportResult = await WebDAVService.instance.exportLocalData();
|
||||||
if (!exportResult.success || exportResult.zipPath == null) {
|
if (!exportResult.success || exportResult.zipPath == null) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => _syncing = false);
|
Navigator.pop(context); // 关闭 bottom sheet
|
||||||
_showResultDialog(title: '同步失败', message: exportResult.errorMessage ?? '创建备份失败', isSuccess: false);
|
_showResultDialog(navigator, title: '同步失败', message: exportResult.errorMessage ?? '创建备份失败', isSuccess: false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -443,22 +446,22 @@ class _CloudSheetContentState extends State<_CloudSheetContent> {
|
|||||||
}
|
}
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => _syncing = false);
|
setState(() => _syncing = false);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context); // 关闭 bottom sheet
|
||||||
_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},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
_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 {
|
} else {
|
||||||
// 下载
|
// 下载
|
||||||
setState(() => _syncStep = '正在从云端下载...');
|
setState(() => _syncStep = '正在从云端下载...');
|
||||||
final config = await WebDAVService.instance.getConfig();
|
final config = await WebDAVService.instance.getConfig();
|
||||||
if (config == null) {
|
if (config == null) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => _syncing = false);
|
Navigator.pop(context);
|
||||||
_showResultDialog(title: '同步失败', message: '请先配置 WebDAV 服务器', isSuccess: false);
|
_showResultDialog(navigator, title: '同步失败', message: '请先配置 WebDAV 服务器', isSuccess: false);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -472,14 +475,14 @@ class _CloudSheetContentState extends State<_CloudSheetContent> {
|
|||||||
}
|
}
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => _syncing = false);
|
setState(() => _syncing = false);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context); // 关闭 bottom sheet
|
||||||
_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},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
_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}) {
|
void _showResultDialog(NavigatorState navigator, {required String title, required String message, required bool isSuccess, Map<String, dynamic>? details}) {
|
||||||
final colors = Theme.of(context).colorScheme;
|
// 使用保存的 navigator context,而非 state context(bottom sheet 已 pop)
|
||||||
|
final overlayCtx = navigator.context;
|
||||||
|
final colors = Theme.of(overlayCtx).colorScheme;
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: overlayCtx,
|
||||||
builder: (dialogCtx) => AlertDialog(
|
builder: (dialogCtx) => AlertDialog(
|
||||||
backgroundColor: colors.surface, elevation: 0,
|
backgroundColor: colors.surface, elevation: 0,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
|||||||
@@ -374,9 +374,14 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colors = Theme.of(context).colorScheme;
|
final colors = Theme.of(context).colorScheme;
|
||||||
return Scaffold(
|
return PopScope(
|
||||||
backgroundColor: colors.surface,
|
canPop: !_isLoading,
|
||||||
appBar: AppBar(title: const Text('WebDAV 备份')),
|
child: Scaffold(
|
||||||
|
backgroundColor: colors.surface,
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('WebDAV 备份'),
|
||||||
|
leading: _isLoading ? const SizedBox.shrink() : null,
|
||||||
|
),
|
||||||
body: Stack(
|
body: Stack(
|
||||||
children: [
|
children: [
|
||||||
ListView(
|
ListView(
|
||||||
@@ -387,6 +392,12 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
|
|||||||
// 已连接提示
|
// 已连接提示
|
||||||
if (_isConfigured) _buildConnectedBanner(colors),
|
if (_isConfigured) _buildConnectedBanner(colors),
|
||||||
|
|
||||||
|
if (_isConfigured) ...[
|
||||||
|
// 远程备份信息卡片(包含操作按钮)
|
||||||
|
_buildRemoteInfoCard(colors),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
],
|
||||||
|
|
||||||
// 服务器配置
|
// 服务器配置
|
||||||
_buildSectionLabel(colors, '服务器配置'),
|
_buildSectionLabel(colors, '服务器配置'),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
@@ -444,12 +455,6 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
|
|||||||
],
|
],
|
||||||
const SizedBox(height: 28),
|
const SizedBox(height: 28),
|
||||||
|
|
||||||
if (_isConfigured) ...[
|
|
||||||
// 远程备份信息卡片(包含操作按钮)
|
|
||||||
_buildRemoteInfoCard(colors),
|
|
||||||
const SizedBox(height: 24),
|
|
||||||
],
|
|
||||||
|
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
_buildTips(colors),
|
_buildTips(colors),
|
||||||
const SizedBox(height: 40),
|
const SizedBox(height: 40),
|
||||||
@@ -457,6 +462,7 @@ class _WebDAVSyncPageState extends State<WebDAVSyncPage> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
name: mooknote
|
name: mooknote
|
||||||
description: "app for tracking movies, books, and notes"
|
description: "app for tracking movies, books, and notes"
|
||||||
publish_to: 'none'
|
publish_to: 'none'
|
||||||
version: 0.2.4
|
version: 0.2.5
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.0
|
sdk: ^3.5.0
|
||||||
|
|||||||
Reference in New Issue
Block a user