新版本插件?

一个Flutter插件,可以实现

  • 检查用户是否安装了最新版本的应用程序。
  • 向用户显示一个带有指向相应应用商店页面的链接的警报。

Dart Packages 页面 上查看更多内容。

Screenshots

安装

将 new_version 添加为 pubspec.yaml 文件中的依赖项。

dependencies:
  new_version: ^0.3.0

用法

main.dart (或您的应用程序初始化所在的位置)中,创建一个 NewVersion 的实例。

final newVersion = NewVersion();

该插件将自动使用您的 Flutter 包标识符来检查应用商店。如果您的应用程序在 Google Play 商店或 Apple App 商店中的标识符不同,您可以通过提供 androidId 和/或 iOSId 的值来覆盖它。

对于 iOS: 如果您的应用程序仅在美国以外的 App Store 提供,您需要将 iOSAppStoreCountry 设置为您要搜索的商店的两位字母国家代码。请参阅 http://en.wikipedia.org/wiki/ ISO_3166-1_alpha-2 以获取 ISO 国家代码列表。

然后,您可以通过两种方式使用该插件。

快速入门

使用应用程序的 BuildContext 调用 showAlertIfNecessary 将检查应用程序是否可以更新,并将自动显示一个平台特定的警报,用户可以使用该警报前往应用商店。

newVersion.showAlertIfNecessary(context: context);

高级?

如果您想创建自定义警报或以不同方式使用应用程序版本信息,请调用 getVersionStatus。这将返回一个 Future<VersionStatus>,其中包含有关应用程序的本地和应用商店版本的信息。

final status = await newVersion.getVersionStatus();
status.canUpdate // (true)
status.localVersion // (1.2.1)
status.storeVersion // (1.2.3)
status.appStoreLink // (https://itunes.apple.com/us/app/google/id284815942?mt=8)

如果您想显示自定义对话框,可以将 VersionStatus 传递给 showUpdateDialog()

newVersion.showUpdateDialog(
  context: context, 
  versionStatus: status,
  dialogTitle: 'Custom dialog title',
  dialogText: 'Custom dialog text',
  updateButtonText: 'Custom update button text',
  dismissButtonText: 'Custom dismiss button text',
  dismissAction: () => functionToRunAfterDialogDismissed(),
)

GitHub

查看 Github