111
This commit is contained in:
parent
36680ec187
commit
87ca82cf87
|
|
@ -1,7 +1,6 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:app_upgrade_plugin/app_upgrade_plugin.dart';
|
import 'package:app_upgrade_plugin/app_upgrade_plugin.dart';
|
||||||
import 'package:app_upgrade_plugin/app_upgrade_plugin_enhanced.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
|
@ -21,13 +20,6 @@ void main() {
|
||||||
// AppUpgradePlugin().configureHttp(HttpConfig.unsafe);
|
// AppUpgradePlugin().configureHttp(HttpConfig.unsafe);
|
||||||
|
|
||||||
// 延迟插件配置到Flutter完全初始化后
|
// 延迟插件配置到Flutter完全初始化后
|
||||||
Future.delayed(Duration.zero, () {
|
|
||||||
AppUpgradePluginEnhanced.instance.configure(
|
|
||||||
debugMode: true,
|
|
||||||
wifiOnly: false,
|
|
||||||
autoCheck: true,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ description: "Demonstrates how to use the app_upgrade_plugin plugin."
|
||||||
# The following line prevents the package from being accidentally published to
|
# The following line prevents the package from being accidentally published to
|
||||||
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
# pub.dev using `flutter pub publish`. This is preferred for private packages.
|
||||||
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
||||||
|
version: 1.0.0+1
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.0 <4.0.0'
|
sdk: '>=3.0.0 <4.0.0'
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,40 @@ import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
|
|
||||||
import 'app_upgrade_plugin.dart';
|
import 'app_upgrade_plugin_platform_interface.dart';
|
||||||
|
import 'core/permission_helper.dart';
|
||||||
import 'core/upgrade_utils.dart';
|
import 'core/upgrade_utils.dart';
|
||||||
|
import 'models/upgrade_info.dart';
|
||||||
|
import 'widgets/market_selection_dialog.dart';
|
||||||
|
|
||||||
|
/// 简化的插件接口,避免循环导入
|
||||||
|
class _SimpleAppUpgradePlugin {
|
||||||
|
static final _SimpleAppUpgradePlugin _instance = _SimpleAppUpgradePlugin._();
|
||||||
|
|
||||||
|
_SimpleAppUpgradePlugin._();
|
||||||
|
|
||||||
|
static _SimpleAppUpgradePlugin get instance => _instance;
|
||||||
|
|
||||||
|
Future<UpgradeInfo?> checkUpdate(String url, {Map<String, dynamic>? params}) {
|
||||||
|
return AppUpgradePluginPlatform.instance.checkUpdate(url, params: params);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<String?> downloadApk(String url, {Function(DownloadProgress)? onProgress}) {
|
||||||
|
return AppUpgradePluginPlatform.instance.downloadApk(url, onProgress: onProgress);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> installApk(String filePath) {
|
||||||
|
return AppUpgradePluginPlatform.instance.installApk(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> goToAppStore(String url) {
|
||||||
|
return AppUpgradePluginPlatform.instance.goToAppStore(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Map<String, String>> getAppInfo() {
|
||||||
|
return AppUpgradePluginPlatform.instance.getAppInfo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 简化版App升级管理器
|
/// 简化版App升级管理器
|
||||||
/// 提供最简单的API,一行代码即可实现App升级功能
|
/// 提供最简单的API,一行代码即可实现App升级功能
|
||||||
|
|
@ -23,11 +55,11 @@ class AppUpgradeSimple {
|
||||||
}
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
AppUpgradeSimple.private({AppUpgradePlugin? plugin}) : _plugin = plugin ?? AppUpgradePlugin();
|
AppUpgradeSimple.private({_SimpleAppUpgradePlugin? plugin}) : _plugin = plugin ?? _SimpleAppUpgradePlugin.instance;
|
||||||
|
|
||||||
AppUpgradeSimple._() : _plugin = AppUpgradePlugin();
|
AppUpgradeSimple._() : _plugin = _SimpleAppUpgradePlugin.instance;
|
||||||
|
|
||||||
final AppUpgradePlugin _plugin;
|
final _SimpleAppUpgradePlugin _plugin;
|
||||||
|
|
||||||
/// 一键检查更新(最简单的使用方式)
|
/// 一键检查更新(最简单的使用方式)
|
||||||
///
|
///
|
||||||
|
|
@ -240,7 +272,7 @@ class _UpgradeDialogContent extends StatelessWidget {
|
||||||
|
|
||||||
/// 共享的升级操作逻辑
|
/// 共享的升级操作逻辑
|
||||||
mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
mixin _UpgradeDialogLogic<T extends StatefulWidget> on State<T> {
|
||||||
final _plugin = AppUpgradePlugin();
|
final _plugin = _SimpleAppUpgradePlugin.instance;
|
||||||
bool _isDownloading = false;
|
bool _isDownloading = false;
|
||||||
double _downloadProgress = 0;
|
double _downloadProgress = 0;
|
||||||
String _statusText = '';
|
String _statusText = '';
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
import '../app_upgrade_plugin.dart';
|
import '../app_upgrade_plugin_platform_interface.dart';
|
||||||
|
|
||||||
/// Enum representing the status of the install permission.
|
/// Enum representing the status of the install permission.
|
||||||
enum InstallPermissionStatus {
|
enum InstallPermissionStatus {
|
||||||
|
|
@ -24,8 +24,6 @@ enum InstallPermissionStatus {
|
||||||
|
|
||||||
/// A helper class for handling permissions required by the app upgrade process.
|
/// A helper class for handling permissions required by the app upgrade process.
|
||||||
class PermissionHelper {
|
class PermissionHelper {
|
||||||
static final _plugin = AppUpgradePlugin();
|
|
||||||
|
|
||||||
/// Checks and requests storage permission (required for downloading files).
|
/// Checks and requests storage permission (required for downloading files).
|
||||||
///
|
///
|
||||||
/// This method handles different Android versions appropriately:
|
/// This method handles different Android versions appropriately:
|
||||||
|
|
@ -196,7 +194,7 @@ class PermissionHelper {
|
||||||
|
|
||||||
if (openSettings) {
|
if (openSettings) {
|
||||||
// 使用精确的安装权限设置页面
|
// 使用精确的安装权限设置页面
|
||||||
final opened = await _plugin.openInstallPermissionSettings();
|
final opened = await AppUpgradePluginPlatform.instance.openInstallPermissionSettings();
|
||||||
if (!opened) {
|
if (!opened) {
|
||||||
// 如果无法打开精确页面,则使用通用应用设置页面作为后备
|
// 如果无法打开精确页面,则使用通用应用设置页面作为后备
|
||||||
await openAppSettings();
|
await openAppSettings();
|
||||||
|
|
@ -221,7 +219,7 @@ class PermissionHelper {
|
||||||
|
|
||||||
if (openSettings) {
|
if (openSettings) {
|
||||||
// 使用精确的安装权限设置页面
|
// 使用精确的安装权限设置页面
|
||||||
final opened = await _plugin.openInstallPermissionSettings();
|
final opened = await AppUpgradePluginPlatform.instance.openInstallPermissionSettings();
|
||||||
if (!opened) {
|
if (!opened) {
|
||||||
// 如果无法打开精确页面,则使用通用应用设置页面作为后备
|
// 如果无法打开精确页面,则使用通用应用设置页面作为后备
|
||||||
await openAppSettings();
|
await openAppSettings();
|
||||||
|
|
@ -313,7 +311,7 @@ class PermissionHelper {
|
||||||
/// Caches the result to avoid repeated platform channel calls.
|
/// Caches the result to avoid repeated platform channel calls.
|
||||||
static Future<int> _getAndroidSdkVersion() async {
|
static Future<int> _getAndroidSdkVersion() async {
|
||||||
if (!Platform.isAndroid) return 0;
|
if (!Platform.isAndroid) return 0;
|
||||||
_sdkVersion ??= await _plugin.getAndroidSdkVersion() ?? 0;
|
_sdkVersion ??= await AppUpgradePluginPlatform.instance.getAndroidSdkVersion() ?? 0;
|
||||||
return _sdkVersion!;
|
return _sdkVersion!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue