From e30aef8b44489152af9751734f4fb7ffefb261d5 Mon Sep 17 00:00:00 2001 From: "DESKTOP-I3JPKHK\\wy" <1111> Date: Thu, 11 Dec 2025 16:39:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86onComplete=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app_upgrade_simple.dart | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/lib/app_upgrade_simple.dart b/lib/app_upgrade_simple.dart index 28dc39b..da6f4de 100644 --- a/lib/app_upgrade_simple.dart +++ b/lib/app_upgrade_simple.dart @@ -226,7 +226,7 @@ class AppUpgradeSimple { required Future Function() future, bool? showNoUpdateToast, bool? autoInstall, - BoolCallback? onComplete, + VoidCallback? onComplete, VoidCallback? onUpdateLater, UpgradeConfig? config, }) async { @@ -239,7 +239,6 @@ class AppUpgradeSimple { final info = await _prepareUpgradeInfo(future: future, config: effectiveConfig); if (info == null) { - onComplete?.call(true); return; } @@ -247,7 +246,6 @@ class AppUpgradeSimple { if (finalShowNoUpdateToast && context.mounted) { _showToast('已是最新版本', context, effectiveConfig); } - onComplete?.call(true); return; } @@ -255,7 +253,6 @@ class AppUpgradeSimple { context: context, info: info, autoInstall: finalAutoInstall, - onComplete: onComplete, onUpdateLater: onUpdateLater, config: effectiveConfig, ); @@ -265,7 +262,8 @@ class AppUpgradeSimple { if (context.mounted) { _showToast('检查更新遇到问题', context, effectiveConfig); } - onComplete?.call(true); + } finally { + onComplete?.call(); } } @@ -308,7 +306,6 @@ class AppUpgradeSimple { required BuildContext context, required UpgradeInfo info, bool? autoInstall, - BoolCallback? onComplete, VoidCallback? onUpdateLater, UpgradeConfig? config, }) async { @@ -324,7 +321,6 @@ class AppUpgradeSimple { if (effectiveConfig.showNoUpdateToast && context.mounted) { _showToast('已是最新版本', context, effectiveConfig); } - onComplete?.call(true); return; } @@ -332,7 +328,6 @@ class AppUpgradeSimple { context: context, info: info, autoInstall: finalAutoInstall, - onComplete: onComplete, onUpdateLater: onUpdateLater, config: effectiveConfig, ); @@ -483,7 +478,6 @@ class AppUpgradeSimple { required BuildContext context, required UpgradeInfo info, required bool autoInstall, - BoolCallback? onComplete, VoidCallback? onUpdateLater, UpgradeConfig? config, }) { @@ -503,7 +497,6 @@ class AppUpgradeSimple { return _SimpleUpgradeDialog( info: info, autoInstall: autoInstall, - onComplete: onComplete, onUpdateLater: onUpdateLater, config: effectiveConfig, showToast: (message) => _showToast(message, context, effectiveConfig), @@ -634,7 +627,6 @@ mixin _UpgradeDialogLogic on State { UpgradeInfo get info; void Function(String) get showToast; - BoolCallback? get onComplete; bool get autoInstall; UpgradeConfig get config; @@ -892,7 +884,6 @@ mixin _UpgradeDialogLogic on State { if (mounted && Navigator.canPop(context)) { Navigator.of(context).pop(); } - onComplete?.call(true); }); } @@ -1737,7 +1728,6 @@ mixin _UpgradeDialogLogic on State { showToast('无法打开App Store,请稍后重试'); } // 移除关闭弹窗代码,始终不关闭 - onComplete?.call(true); } else { showToast('App Store URL is not available.'); } @@ -1830,7 +1820,6 @@ mixin _UpgradeDialogLogic on State { Future _handleMarketAction() async { if (!mounted) return; await _performMarketAction(); - onComplete?.call(true); // 移除关闭弹窗代码 } @@ -1936,7 +1925,6 @@ mixin _UpgradeDialogLogic on State { // 不再关闭弹窗,即使用户选择了更新方式 if (choice == AppUpgradeMethod.market) { await _performMarketAction(); - onComplete?.call(true); return; } @@ -1954,7 +1942,6 @@ mixin _UpgradeDialogLogic on State { class _SimpleUpgradeDialog extends StatefulWidget { final UpgradeInfo info; final bool autoInstall; - final BoolCallback? onComplete; final VoidCallback? onUpdateLater; final void Function(String) showToast; final UpgradeConfig config; @@ -1962,7 +1949,6 @@ class _SimpleUpgradeDialog extends StatefulWidget { const _SimpleUpgradeDialog({ required this.info, required this.autoInstall, - this.onComplete, this.onUpdateLater, required this.showToast, required this.config, @@ -1977,8 +1963,7 @@ class _SimpleUpgradeDialogState extends State<_SimpleUpgradeDialog> with _Upgrad UpgradeInfo get info => widget.info; @override void Function(String) get showToast => widget.showToast; - @override - BoolCallback? get onComplete => widget.onComplete; + VoidCallback? get onUpdateLater => widget.onUpdateLater; @override bool get autoInstall => widget.autoInstall; @@ -2066,8 +2051,7 @@ class _SimpleUpgradeDialogState extends State<_SimpleUpgradeDialog> with _Upgrad TextButton( onPressed: () { Navigator.of(context).pop(); - widget.onComplete?.call(false); - widget.onUpdateLater?.call(); + onUpdateLater?.call(); }, child: const Text('稍后更新'), ), @@ -2108,8 +2092,6 @@ class _ForceUpgradeDialogState extends State<_ForceUpgradeDialog> with _UpgradeD void Function(String) get showToast => (message) => AppUpgradeSimple.instance._showToast(message, context, widget.config); @override - BoolCallback? get onComplete => null; - @override bool get autoInstall => widget.autoInstall; @override UpgradeConfig get config => widget.config; @@ -2266,8 +2248,6 @@ class _ToastWidget extends StatelessWidget { } } -typedef BoolCallback = void Function(bool success); - class _RichTextStyles { _RichTextStyles(ColorScheme colorScheme) : boldStyle = TextStyle(