Flutter App Store Checker
一个功能强大的 Flutter 插件,用于检测 iOS 应用在 App Store 是否有新版本,支持自定义主题和多种使用方式。
🚀 功能特性
- ✅ 自动包名获取 - 自动获取当前应用的包名 (Bundle ID)
- ✅ 测试包名支持 - 支持传入自定义包名进行测试
- ✅ 版本检测 - 检测 App Store 是否有新版本
- ✅ 应用信息获取 - 获取应用详细信息(版本、更新说明、评分等)
- ✅ 存在性检查 - 检查包名是否在 App Store 存在
- ✅ 双UI模式 - 提供弹窗和页面两种 UI 展示方式
- ✅ 主题定制 - 支持自定义主题色配置
- ✅ 智能缓存 - 支持缓存机制,避免频繁请求
- ✅ 完整错误处理 - 完善的错误处理和状态管理
📦 安装
在 pubspec.yaml 中添加依赖:
dependencies:
flutter_appstore_checker: ^0.1.2
然后运行:
flutter pub get
🎯 快速开始
1. 导入包
import 'package:flutter_appstore_checker/flutter_appstore_checker.dart';
2. 基本使用
检测应用更新
// 检测当前应用是否有更新
final result = await AppUpdateChecker.instance.checkUpdate();
if (result.success && result.hasNewVersion) {
print('发现新版本: ${result.latestVersion}');
print('当前版本: ${result.currentVersion}');
print('更新说明: ${result.releaseNotes}');
}
// 使用指定包名检测
final result = await AppUpdateChecker.instance.checkUpdate(
bundleId: 'com.tencent.xin',
forceCheck: true,
);
检查应用是否存在
// 检查当前应用是否在 App Store 存在
final exists = await AppUpdateChecker.instance.isAppExistsInAppStore();
// 检查指定包名是否存在
final exists = await AppUpdateChecker.instance.isAppExistsInAppStore(
bundleId: 'com.tencent.xin',
);
print(exists ? '应用存在' : '应用不存在');
获取应用详细信息
// 获取应用的 App Store 信息
final appInfo = await AppUpdateChecker.instance.getAppStoreInfo(
bundleId: 'com.tencent.xin',
);
if (appInfo != null) {
print('应用名称: ${appInfo.trackName}');
print('最新版本: ${appInfo.version}');
print('应用评分: ${appInfo.averageRating}');
print('评分数量: ${appInfo.ratingCount}');
}
🎨 UI 组件
更新检测页面
// 基本使用
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AppUpdatePage(),
),
);
// 使用测试包名和自定义主题
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AppUpdatePage(
testBundleId: 'com.tencent.xin',
theme: AppUpdateTheme.blueTheme,
),
),
);
更新弹窗
// 检测并显示更新弹窗
final hasUpdate = await AppUpdateDialog.checkAndShow(
context,
forceCheck: true,
);
// 使用自定义主题和包名,隐藏更新内容
final hasUpdate = await AppUpdateDialog.checkAndShow(
context,
bundleId: 'com.tencent.xin',
theme: AppUpdateTheme(primaryColor: Colors.purple),
showReleaseNotes: false, // 隐藏更新内容
);
🎨 主题定制
预设主题
// 使用预设主题
AppUpdateTheme.defaultTheme // 橙色主题(默认)
AppUpdateTheme.blueTheme // 蓝色主题
AppUpdateTheme.purpleTheme // 紫色主题
AppUpdateTheme.greenTheme // 绿色主题
AppUpdateTheme.redTheme // 红色主题
自定义主题
// 创建自定义主题
final customTheme = AppUpdateTheme(
primaryColor: Colors.indigo,
successColor: Colors.teal,
errorColor: Colors.deepOrange,
warningColor: Colors.amber,
);
// 从当前上下文创建主题
final contextTheme = AppUpdateTheme.fromContext(context);
// 复制并修改主题
final modifiedTheme = AppUpdateTheme.defaultTheme.copyWith(
primaryColor: Colors.pink,
);
🔧 高级功能
缓存管理
// 设置缓存有效期(默认5分钟)
AppUpdateChecker.instance.setCacheValidDuration(
const Duration(minutes: 10),
);
// 清除缓存
AppUpdateChecker.instance.clearCache();
// 检查缓存状态
if (AppUpdateChecker.instance.hasCachedResult) {
final cachedResult = AppUpdateChecker.instance.cachedResult;
print('缓存有效: ${AppUpdateChecker.instance.isCacheValid}');
}
直接使用服务
// 获取 App Store 信息
final appInfo = await AppStoreService.fetchAppInfo('com.tencent.xin');
// 根据应用ID获取信息
final appInfo = await AppStoreService.fetchAppInfoById('123456789');
// 搜索应用
final apps = await AppStoreService.searchApps('微信', limit: 5);
版本工具
// 版本比较
final isNewer = VersionUtils.isNewerVersion('1.0.0', '1.0.1'); // true
// 版本格式化
final formatted = VersionUtils.formatVersion('1.0.0', '100'); // v1.0.0 (100)
// 版本验证
final isValid = VersionUtils.isValidVersion('1.0.0'); // true
📚 API 参考
AppUpdateChecker
主要的更新检测类(单例模式)
| 方法 | 描述 |
|---|---|
checkUpdate() |
检测应用更新 |
isAppExistsInAppStore() |
检查应用是否存在 |
getAppStoreInfo() |
获取应用详细信息 |
openAppStore() |
打开 App Store |
clearCache() |
清除缓存 |
setCacheValidDuration() |
设置缓存有效期 |
AppUpdateTheme
主题配置类
| 属性 | 类型 | 描述 |
|---|---|---|
primaryColor |
Color | 主题色 |
successColor |
Color | 成功色 |
errorColor |
Color | 错误色 |
warningColor |
Color | 警告色 |
UpdateCheckResult
更新检测结果
| 属性 | 类型 | 描述 |
|---|---|---|
success |
bool | 检测是否成功 |
hasNewVersion |
bool | 是否有新版本 |
currentVersion |
String | 当前版本 |
latestVersion |
String | 最新版本 |
bundleId |
String | 应用包名 |
storeInfo |
AppStoreInfo? | App Store 信息 |
errorMessage |
String? | 错误信息 |
AppStoreInfo
App Store 应用信息
| 属性 | 类型 | 描述 |
|---|---|---|
appId |
String | 应用 ID |
version |
String | 版本号 |
trackName |
String | 应用名称 |
releaseNotes |
String | 更新说明 |
appStoreUrl |
String | App Store 链接 |
artworkUrl |
String | 应用图标链接 |
averageRating |
double | 平均评分 |
ratingCount |
int | 评分数量 |
📱 示例截图
更新检测页面
- 支持测试包名输入
- 显示应用图标和详细信息
- 检查包名是否存在功能
- 自定义主题色支持
更新弹窗
- 简洁的弹窗设计
- 显示应用图标和名称
- 版本对比信息
- 更新内容展示
⚠️ 注意事项
- 平台支持: 此插件仅支持 iOS 平台的 App Store 检测
- 应用要求: 需要应用已在 App Store 上架才能检测到信息
- 网络请求: 建议设置合理的缓存时间,避免频繁请求 Apple 服务器
- 错误处理: 网络请求可能失败,请做好错误处理
- 测试建议: 使用
com.tencent.xin(微信) 等已上架的应用包名进行测试
🔗 相关链接
📄 许可证
MIT License - 详见 LICENSE 文件