111
This commit is contained in:
parent
4b9fa0ee85
commit
3ec968802a
|
|
@ -2,7 +2,9 @@ import 'dart:io';
|
|||
|
||||
// 确保方法通道实现被导入,以便正确初始化
|
||||
// ignore: unused_import
|
||||
import 'app_upgrade_plugin_method_channel.dart';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import 'app_upgrade_plugin_platform_interface.dart';
|
||||
import 'core/http_config.dart';
|
||||
import 'models/install_strategy.dart';
|
||||
|
|
@ -14,12 +16,12 @@ export 'app_upgrade_simple.dart';
|
|||
export 'core/http_config.dart';
|
||||
// 权限帮助类
|
||||
export 'core/permission_helper.dart';
|
||||
export 'models/install_strategy.dart';
|
||||
export 'models/upgrade_info.dart';
|
||||
// 导出新定义的模型
|
||||
export 'models/app_upgrade_version.dart';
|
||||
// 导出升级方式枚举
|
||||
export 'models/app_upgrade_method.dart';
|
||||
// 导出新定义的模型
|
||||
export 'models/app_upgrade_version.dart';
|
||||
export 'models/install_strategy.dart';
|
||||
export 'models/upgrade_info.dart';
|
||||
// 导出市场选择对话框(其他对话框已整合到简化API中)
|
||||
export 'widgets/widgets.dart';
|
||||
|
||||
|
|
@ -167,8 +169,8 @@ class AppUpgradePlugin {
|
|||
|
||||
/// 跳转到应用商店
|
||||
/// [url] 应用商店地址
|
||||
Future<bool> goToAppStore(String url) {
|
||||
return AppUpgradePluginPlatform.instance.goToAppStore(url);
|
||||
Future<bool> goToAppStore(String url, {required BuildContext context}) {
|
||||
return AppUpgradePluginPlatform.instance.goToAppStore(url, context: context);
|
||||
}
|
||||
|
||||
/// 获取下载目录路径
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@ import 'dart:io';
|
|||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
|
@ -487,7 +486,7 @@ class MethodChannelAppUpgradePlugin extends AppUpgradePluginPlatform {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<bool> goToAppStore(String url) async {
|
||||
Future<bool> goToAppStore(String url, {required BuildContext context}) async {
|
||||
try {
|
||||
final uri = Uri.parse(url);
|
||||
final bool flag = await canLaunchUrl(uri);
|
||||
|
|
@ -495,7 +494,14 @@ class MethodChannelAppUpgradePlugin extends AppUpgradePluginPlatform {
|
|||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
return true;
|
||||
}
|
||||
Fluttertoast.showToast(msg: '当前APP没有上架当前设备对应的应用市场');
|
||||
debugPrint('当前APP没有上架当前设备对应的应用市场');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('当前APP没有上架当前设备对应的应用市场'),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
// Fluttertoast.showToast(msg: '当前APP没有上架当前设备对应的应用市场');
|
||||
return false;
|
||||
} catch (e) {
|
||||
debugPrint('跳转应用商店失败: $e');
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'app_upgrade_plugin_method_channel.dart';
|
||||
|
|
@ -82,7 +83,7 @@ abstract class AppUpgradePluginPlatform extends PlatformInterface {
|
|||
}
|
||||
|
||||
/// 跳转到应用商店
|
||||
Future<bool> goToAppStore(String url) {
|
||||
Future<bool> goToAppStore(String url, {required BuildContext context}) {
|
||||
throw UnimplementedError('goToAppStore() has not been implemented.');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'dart:async';
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import 'app_upgrade_plugin_platform_interface.dart';
|
||||
|
|
@ -33,8 +32,8 @@ class _SimpleAppUpgradePlugin {
|
|||
return AppUpgradePluginPlatform.instance.installApk(filePath);
|
||||
}
|
||||
|
||||
Future<bool> goToAppStore(String url) {
|
||||
return AppUpgradePluginPlatform.instance.goToAppStore(url);
|
||||
Future<bool> goToAppStore(String url, {required BuildContext context}) {
|
||||
return AppUpgradePluginPlatform.instance.goToAppStore(url, context: context);
|
||||
}
|
||||
|
||||
Future<Map<String, String>> getAppInfo() {
|
||||
|
|
@ -283,7 +282,7 @@ class AppUpgradeSimple {
|
|||
|
||||
if (!info.hasUpdate) {
|
||||
if (finalShowNoUpdateToast && context.mounted) {
|
||||
_showToast('已是最新版本', effectiveConfig);
|
||||
_showToast('已是最新版本', context, effectiveConfig);
|
||||
}
|
||||
onComplete?.call();
|
||||
return;
|
||||
|
|
@ -301,7 +300,7 @@ class AppUpgradeSimple {
|
|||
debugPrint('检查更新失败: $e');
|
||||
|
||||
if (context.mounted) {
|
||||
_showToast('检查更新遇到问题', effectiveConfig);
|
||||
_showToast('检查更新遇到问题', context, effectiveConfig);
|
||||
}
|
||||
onComplete?.call();
|
||||
}
|
||||
|
|
@ -460,7 +459,7 @@ class AppUpgradeSimple {
|
|||
autoInstall: autoInstall,
|
||||
onComplete: onComplete,
|
||||
config: effectiveConfig,
|
||||
showToast: (message) => _showToast(message, effectiveConfig),
|
||||
showToast: (message) => _showToast(message, context, effectiveConfig),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
|
@ -468,18 +467,16 @@ class AppUpgradeSimple {
|
|||
}
|
||||
|
||||
/// 显示Toast提示
|
||||
void _showToast(String message, [UpgradeConfig? config]) {
|
||||
void _showToast(String message, BuildContext context, [UpgradeConfig? config]) {
|
||||
final effectiveConfig = config ?? _config;
|
||||
if (effectiveConfig.customToast != null) {
|
||||
effectiveConfig.customToast!(message);
|
||||
} else {
|
||||
Fluttertoast.showToast(
|
||||
msg: message,
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
backgroundColor: Colors.black87,
|
||||
textColor: Colors.white,
|
||||
fontSize: 14.0,
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('这是一个SnackBar提示'),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1515,15 +1512,15 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
if (Platform.isAndroid) {
|
||||
_handleAndroidAction();
|
||||
} else if (Platform.isIOS) {
|
||||
_handleIosAction();
|
||||
_handleIosAction(context);
|
||||
} else {
|
||||
showToast('Unsupported platform');
|
||||
}
|
||||
}
|
||||
|
||||
void _handleIosAction() {
|
||||
void _handleIosAction(BuildContext context) {
|
||||
if (info.appStoreUrl != null) {
|
||||
_plugin.goToAppStore(info.appStoreUrl!);
|
||||
_plugin.goToAppStore(info.appStoreUrl!, context: context);
|
||||
// 移除关闭弹窗代码,始终不关闭
|
||||
onComplete?.call();
|
||||
} else {
|
||||
|
|
@ -1581,14 +1578,14 @@ mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
|||
context,
|
||||
markets: info.appMarkets!,
|
||||
onSelected: (market) {
|
||||
_plugin.goToAppStore(market.url ?? market.packageName ?? '');
|
||||
_plugin.goToAppStore(market.url ?? market.packageName ?? '', context: context);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
final appInfo = await _plugin.getAppInfo();
|
||||
final pkg = appInfo['packageName'] ?? '';
|
||||
if (pkg.isNotEmpty) {
|
||||
_plugin.goToAppStore('market://details?id=$pkg');
|
||||
_plugin.goToAppStore('market://details?id=$pkg', context: context);
|
||||
// _plugin.goToAppStore('market://details?id=com.yuanxuan.learningOfficerOa');
|
||||
} else {
|
||||
showToast('Could not determine app package name.');
|
||||
|
|
@ -1866,7 +1863,8 @@ class _ForceUpgradeDialogState extends State<_ForceUpgradeDialog> with _UpgradeD
|
|||
@override
|
||||
UpgradeInfo get info => widget.info;
|
||||
@override
|
||||
void Function(String) get showToast => (message) => AppUpgradeSimple.instance._showToast(message, widget.config);
|
||||
void Function(String) get showToast =>
|
||||
(message) => AppUpgradeSimple.instance._showToast(message, context, widget.config);
|
||||
@override
|
||||
VoidCallback? get onComplete => null;
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ dependencies:
|
|||
shared_preferences: ^2.3.3
|
||||
flutter_local_notifications: ^18.0.1
|
||||
device_info_plus: ^11.2.0
|
||||
fluttertoast: ^9.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class MockAppUpgradePluginPlatform extends AppUpgradePluginPlatform with MockPla
|
|||
}
|
||||
|
||||
@override
|
||||
Future<bool> goToAppStore(String url) async {
|
||||
Future<bool> goToAppStore(String url, {required BuildContext context}) async {
|
||||
goToAppStoreCalled = true;
|
||||
lastUrl = url;
|
||||
return true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue