diff --git a/lib/app_upgrade_simple.dart b/lib/app_upgrade_simple.dart index abfa7f6..4e14d01 100644 --- a/lib/app_upgrade_simple.dart +++ b/lib/app_upgrade_simple.dart @@ -198,6 +198,58 @@ class AppUpgradeSimple { } /// 一键检查更新(支持配置) + /// + /// 参数说明: + /// - [context] (必需) BuildContext,用于显示升级对话框,必须在 MaterialApp 环境内调用 + /// - [future] (必需) 异步函数,用于获取服务器版本信息,返回 [AppUpgradeVersion] 对象或 null + /// - 返回 null 时视为无更新 + /// - 返回 [AppUpgradeVersion] 时,会与当前版本比较,决定是否显示升级对话框 + /// - [showNoUpdateToast] (可选) 是否显示"已是最新版本"的提示 + /// - true: 无更新时显示提示(默认) + /// - false: 无更新时不显示提示 + /// - null: 使用 [config] 或全局配置的 [UpgradeConfig.showNoUpdateToast] + /// - [autoDownload] (可选) 是否自动下载APK + /// - true: 检测到新版本后自动开始下载 + /// - false: 需要用户点击"立即更新"按钮才开始下载(默认) + /// - null: 使用 [config] 或全局配置的 [UpgradeConfig.autoDownload] + /// - [autoInstall] (可选) 是否自动安装APK + /// - true: 下载完成后自动触发安装流程 + /// - false: 下载完成后需要用户手动触发安装(默认) + /// - null: 使用 [config] 或全局配置的 [UpgradeConfig.autoInstall] + /// - 注意:仅在 [autoDownload] 为 true 时生效 + /// - [onComplete] (可选) 完成回调函数 + /// - 在以下情况会被调用: + /// - 检查完成(无论是否有更新) + /// - 检查失败 + /// - 用户关闭升级对话框 + /// - [config] (可选) 升级配置对象 [UpgradeConfig] + /// - 如果提供,会覆盖全局配置和单个参数设置 + /// - 如果为 null,使用全局配置 [UpgradeConfig] + /// - 配置项包括:超时时间、调试日志、权限要求等 + /// + /// 使用示例: + /// ```dart + /// await AppUpgradeSimple.instance.checkUpdate( + /// context: context, + /// future: () async { + /// // 调用您的API获取版本信息 + /// final response = await http.get('https://api.example.com/version'); + /// return AppUpgradeVersion.fromJson(json.decode(response.body)); + /// }, + /// showNoUpdateToast: true, + /// autoDownload: false, + /// autoInstall: false, + /// onComplete: () { + /// print('检查更新完成'); + /// }, + /// ); + /// ``` + /// + /// 参数优先级: + /// 1. 方法参数(如 [showNoUpdateToast], [autoDownload], [autoInstall]) + /// 2. [config] 参数中的配置 + /// 3. 全局配置(通过 [configure] 方法设置) + /// 4. 默认配置 Future checkUpdate({ required BuildContext context, required Future Function() future,