修复并调整部分BUG

This commit is contained in:
DESKTOP-I3JPKHK\wy 2025-11-26 14:37:55 +08:00
parent 98cdfe7fb6
commit a444566fcc
2 changed files with 66 additions and 61 deletions

View File

@ -85,7 +85,7 @@ class _HomePageState extends State<HomePage> {
supportedMethods: [AppUpgradeMethod.browser, AppUpgradeMethod.inApp, AppUpgradeMethod.market],
);
},
showNoUpdateToast: true,
showNoUpdateToast: false, // "已是最新版本"
autoDownload: false,
autoInstall: true,
);
@ -139,7 +139,7 @@ class _HomePageState extends State<HomePage> {
downloadUrl: 'https://example.com/app.apk',
);
},
showNoUpdateToast: true,
showNoUpdateToast: false, // "已是最新版本"
autoDownload: false,
autoInstall: false,
);

View File

@ -1,12 +1,12 @@
import 'dart:async';
import 'dart:io';
import 'package:app_upgrade_plugin/core/upgrade_utils.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import 'app_upgrade_plugin_platform_interface.dart';
import 'core/permission_helper.dart';
import 'core/upgrade_utils.dart';
import 'models/app_upgrade_method.dart';
import 'models/app_upgrade_version.dart';
import 'models/upgrade_info.dart';
@ -217,11 +217,12 @@ class AppUpgradeSimple {
/// - false:
/// - null: 使 [config] [UpgradeConfig.autoInstall]
/// - [autoDownload] true
/// - [onComplete] ()
/// - [onComplete] () bool
/// - true:
/// - false:
/// -
/// -
/// -
/// -
/// -
/// - [config] () [UpgradeConfig]
/// -
/// - null使 [UpgradeConfig]
@ -239,8 +240,8 @@ class AppUpgradeSimple {
/// showNoUpdateToast: true,
/// autoDownload: false,
/// autoInstall: false,
/// onComplete: () {
/// print('检查更新完成');
/// onComplete: (success) {
/// print('检查更新完成,结果: $success');
/// },
/// );
/// ```
@ -256,7 +257,7 @@ class AppUpgradeSimple {
bool? showNoUpdateToast,
bool? autoDownload,
bool? autoInstall,
VoidCallback? onComplete,
BoolCallback? onComplete,
UpgradeConfig? config,
}) async {
// 使
@ -270,11 +271,11 @@ class AppUpgradeSimple {
// 1.
final serverInfo = await future();
if (serverInfo == null) {
//
//
if (effectiveConfig.enableDebugLog) {
debugPrint('🔍 检查更新结果: 未返回版本信息');
}
onComplete?.call();
onComplete?.call(true);
return;
}
@ -336,7 +337,7 @@ class AppUpgradeSimple {
if (finalShowNoUpdateToast && context.mounted) {
_showToast('已是最新版本', context, effectiveConfig);
}
onComplete?.call();
onComplete?.call(true);
return;
}
@ -354,7 +355,7 @@ class AppUpgradeSimple {
if (context.mounted) {
_showToast('检查更新遇到问题', context, effectiveConfig);
}
onComplete?.call();
onComplete?.call(true);
}
}
@ -490,7 +491,7 @@ class AppUpgradeSimple {
required UpgradeInfo info,
required bool autoDownload,
required bool autoInstall,
VoidCallback? onComplete,
BoolCallback? onComplete,
UpgradeConfig? config,
}) {
final effectiveConfig = config ?? _config;
@ -639,7 +640,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
UpgradeInfo get info;
void Function(String) get showToast;
VoidCallback? get onComplete;
BoolCallback? get onComplete;
bool get autoDownload;
bool get autoInstall;
UpgradeConfig get config;
@ -904,7 +905,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
if (mounted && Navigator.canPop(context)) {
Navigator.of(context).pop();
}
onComplete?.call();
onComplete?.call(true);
});
}
@ -1027,24 +1028,20 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
colorScheme: colorScheme,
),
),
],
),
if (info.apkSize != null) ...[
const SizedBox(height: 8),
Row(
children: [
const SizedBox(width: 8),
Expanded(
child: _buildInfoChip(
context,
icon: Icons.file_download,
label: '大小',
label: '新版体积',
value: formatBytes(info.apkSize!),
colorScheme: colorScheme,
),
),
],
),
],
),
],
),
);
@ -1058,7 +1055,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
required ColorScheme colorScheme,
}) {
return Container(
padding: const EdgeInsets.all(8),
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
decoration: BoxDecoration(
color: colorScheme.surface,
borderRadius: BorderRadius.circular(8),
@ -1087,7 +1084,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
),
],
),
const SizedBox(height: 2),
const SizedBox(height: 4),
Text(
value,
style: TextStyle(
@ -1127,10 +1124,10 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
),
],
),
const SizedBox(height: 12),
const SizedBox(height: 6),
Container(
width: double.infinity,
constraints: const BoxConstraints(maxHeight: 200),
constraints: const BoxConstraints(maxHeight: 300),
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: colorScheme.surfaceContainerHighest.withOpacity(0.3),
@ -1657,7 +1654,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
if (info.appStoreUrl != null) {
_plugin.goToAppStore(info.appStoreUrl!, context: context);
//
onComplete?.call();
onComplete?.call(true);
} else {
showToast('App Store URL is not available.');
}
@ -1731,7 +1728,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
Future<void> _handleMarketAction() async {
if (!mounted) return;
await _performMarketAction();
onComplete?.call();
onComplete?.call(true);
//
}
@ -1768,8 +1765,15 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
child: Stack(
alignment: Alignment.center,
children: [
const Text('选择更新方式', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
if (!info.isForceUpdate)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
child: Text('选择更新方式',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold))),
],
),
Positioned(
right: -12,
child: IconButton(
@ -1802,7 +1806,6 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
onTap: () => Navigator.of(ctx).pop(AppUpgradeMethod.browser),
),
const Divider(height: 24),
if (!info.isForceUpdate)
SizedBox(
width: double.infinity,
child: ElevatedButton(
@ -1831,7 +1834,7 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
// 使
if (choice == AppUpgradeMethod.market) {
await _performMarketAction();
onComplete?.call();
onComplete?.call(true);
return;
}
@ -1850,7 +1853,7 @@ class _SimpleUpgradeDialog extends StatefulWidget {
final UpgradeInfo info;
final bool autoDownload;
final bool autoInstall;
final VoidCallback? onComplete;
final BoolCallback? onComplete;
final void Function(String) showToast;
final UpgradeConfig config;
@ -1873,7 +1876,7 @@ class _SimpleUpgradeDialogState extends State<_SimpleUpgradeDialog> with _Upgrad
@override
void Function(String) get showToast => widget.showToast;
@override
VoidCallback? get onComplete => widget.onComplete;
BoolCallback? get onComplete => widget.onComplete;
@override
bool get autoDownload => widget.autoDownload;
@override
@ -1962,7 +1965,7 @@ class _SimpleUpgradeDialogState extends State<_SimpleUpgradeDialog> with _Upgrad
TextButton(
onPressed: () {
Navigator.of(context).pop();
widget.onComplete?.call();
widget.onComplete?.call(false);
},
child: const Text('稍后更新'),
),
@ -2001,7 +2004,7 @@ class _ForceUpgradeDialogState extends State<_ForceUpgradeDialog> with _UpgradeD
void Function(String) get showToast =>
(message) => AppUpgradeSimple.instance._showToast(message, context, widget.config);
@override
VoidCallback? get onComplete => null;
BoolCallback? get onComplete => null;
@override
bool get autoDownload => false;
@override
@ -2040,7 +2043,7 @@ class _ForceUpgradeDialogState extends State<_ForceUpgradeDialog> with _UpgradeD
child: Container(
width: 320,
constraints: const BoxConstraints(
maxHeight: 600,
maxHeight: 700,
),
child: Column(
mainAxisSize: MainAxisSize.min,
@ -2168,3 +2171,5 @@ class _ToastWidget extends StatelessWidget {
);
}
}
typedef BoolCallback = void Function(bool success);