From 716237ef8067d81c66fe5136b8dfacdc2afd7c4f Mon Sep 17 00:00:00 2001 From: ngfchl Date: Sun, 19 Jul 2026 00:18:27 +0800 Subject: [PATCH] provide reliable settings save feedback --- lib/pages/settings_page.dart | 47 ++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart index 0eb60ac..9a323cb 100644 --- a/lib/pages/settings_page.dart +++ b/lib/pages/settings_page.dart @@ -20,6 +20,7 @@ class SettingsDialog extends ConsumerStatefulWidget { class _SettingsDialogState extends ConsumerState { _SettingsTab _activeTab = _SettingsTab.general; + var _saving = false; final _tmdbApiKeyController = TextEditingController(); final _tmdbImageProxyController = TextEditingController(); final _httpProxyHostController = TextEditingController(); @@ -85,16 +86,22 @@ class _SettingsDialogState extends ConsumerState { description: const Text('应用外观、网络任务与影视资料'), actions: [ ShadButton.outline( - onPressed: () => Navigator.of(context).pop(), + onPressed: _saving ? null : () => Navigator.of(context).pop(), child: const Text('取消'), ), ShadButton( - leading: const Icon(Icons.check_rounded, size: 16), - child: const Text('保存设置'), - onPressed: () async { - await _saveSettings(); - if (context.mounted) Navigator.of(context).pop(); - }, + onPressed: _saving ? null : _saveAndClose, + leading: _saving + ? SizedBox( + width: 16, + height: 16, + child: CircularProgressIndicator( + strokeWidth: 2, + color: cs.primaryForeground, + ), + ) + : const Icon(Icons.check_rounded, size: 16), + child: Text(_saving ? '正在保存' : '保存设置'), ), ], child: SizedBox( @@ -405,6 +412,32 @@ class _SettingsDialogState extends ConsumerState { ref.read(mediaLibraryProvider.notifier).updateCloudIndexRefreshSchedule(); } + Future _saveAndClose() async { + setState(() => _saving = true); + try { + await _saveSettings(); + if (!mounted) return; + ShadSonner.maybeOf(context)?.show( + const ShadToast( + title: Text('设置已保存'), + description: Text('新的配置已应用到后续任务。'), + showCloseIconOnlyWhenHovered: false, + ), + ); + Navigator.of(context).pop(); + } catch (error) { + if (!mounted) return; + ShadSonner.maybeOf(context)?.show( + ShadToast.destructive( + title: const Text('保存设置失败'), + description: Text(error.toString()), + showCloseIconOnlyWhenHovered: false, + ), + ); + setState(() => _saving = false); + } + } + String _themeModeToString(ThemeMode mode) { switch (mode) { case ThemeMode.light: