Powerful Flutter App upgrade feature

Note: Unless otherwise specified, Flutter version and Dart versions are as follows:

  • Flutter Version: 1.12.13 + hotfix.5
  • Dart Version: 2.7.0

Application upgrade functionality is one of the basic functions of App, if not this feature will cause the user can not be upgraded, bug or new application functionality and old customers can not touch up, and even the loss of this part of the user.

The importance of the application upgrade functionality eliminates the need to say, here are a few ways under application upgrade functionality, speaking from the platform:

  • IOS platform, the application upgrade functionality can only be upgraded by going to the app store.
  • Android platform, both can be upgraded by going to market application, you can also download the apk package upgrade.

Respectively, and may be forced to upgrade non-mandatory upgrade from compulsory for:

  • Mandatory upgrade: is that users must upgrade in order to continue using the App, if not very necessary not recommend the use of such a strong way, the user can cause resentment.
  • Non-mandatory upgrade is to allow the user clicks "Cancel" to continue to use App.

The following were introduced IOS and Android upgrade process.

IOS upgrade process

IOS upgrade process is as follows:

Flow Description:

  1. Normally we would have access to back-end interface to obtain whether the new version, if there is a new version of the pop-up boxes to determine whether the current version is "mandatory upgrade" if it is only to provide the user a "upgrade" button, otherwise provide users " upgrade "and" cancel "button.
  2. After the system prompts the user to select whether to upgrade, if you select "Cancel" prompt box disappears, if you choose "upgrade" to jump to the app store to upgrade.

Android upgrade process

Ios compared to the upgrade process, Android on the slightly complicated, a flowchart is as follows:

Flow Description:

  1. Access interface to obtain the background if a new version of IOS, and here is the same, there are pop-up prompt box upgrade, to determine whether the current version is "mandatory upgrade" if it is only to provide the user a "upgrade" button, otherwise provide users "upgrade" and "cancel" button.
  2. After the system prompts users to choose whether to upgrade, if you select "Cancel" prompt box disappears, if you choose "upgrade" to jump to judge the market to upgrade or application upgrade by downloading apk.
  3. If the download apk upgrade, start the download apk, apk after the download is complete Jump to install the boot interface.
  4. Jump to the market if the application upgrade, to determine whether a given application market, for example, only Huawei application market shelves, you need to specify at this time jump to Huawei's application market, even if you have many applications to hit the market, it should be based on the user phone installed application market a specified application market, allowing users to select the applications market is not a good experience, but users do not know to which market update, if the user selects an application you do not have shelves of the market, it would be more embarrassing.
  5. Jump directly to a specific application market update after a specified interface applications.

Introduced over the upgrade process, the protagonist finally played.

App upgrade function using the introduction

Just at home initStatecalling upgrading detection methods:

@override
  void initState() {
    AppUpgrade.appUpgrade(
      context,
      _checkAppInfo(),
      iosAppId: 'id88888888',
    );
    super.initState();
  }

_checkAppInfoWays to access back-end interface to obtain if a new version of the information, return Future<AppUpgradeInfo>type, AppUpgradeInfocontaining title, upgrades, apk download url, whether to force the upgrade version.

iosAppIdParameters for jumping to app store.

_checkAppInfo()The method is usually backstage access the interface, the new version information directly back here, as follows:

Future<AppUpgradeInfo> _checkAppInfo() {
  return Future.value(AppUpgradeInfo(
    title: '新版本V1.1.1',
    contents: [
      '1、支持立体声蓝牙耳机,同时改善配对性能',
      '2、提供屏幕虚拟键盘',
      '3、更简洁更流畅,使用起来更快',
      '4、修复一些软件在使用时自动退出bug',
      '5、新增加了分类查看功能'
    ],
    apkDownloadUrl: '',
    force: false,
  ));

Well, the basic functionality of the upgrade is complete, pop-up boxes effect is as follows:

Click on "later" prompt box disappears, click the "experience" automatically differentiate between different platforms.

Background information access interface to obtain a new version of the general needs of the current App package name and version, query methods as follows:

await FlutterUpgrade.appInfo

Type returns AppInfo:

  • versionName: version number, such as 1.0.0.
  • versionCode: Android unique version number, the corresponding Android build.gradle in versionCode, ios return to "0."
  • packageName: package name, corresponding to the Android build.gradle applicationId, ios of BundleIdentifier.

iOS platform upgrade

iOS app store platform to jump directly to the relevant page, iosAppIdmust be set, otherwise the app store can not find the application.

Android platform download apk

Android platform will determine whether a apk download url, if you set the download apk download directly, the effect is as follows:

When the download is complete jump directly to the interface mounting guide apk effect is as follows:

Click Allow user, the following interface:

Click to proceed with the installation, the installation boot screen is above the system interface, different phones or different Android versions will be slightly different.

Jump Android platform application market

If you do not provide apk download address, click the "experience", you'll jump to the application market, the market is not specified prompt box will pop up, allowing users to select the applications market, the effect is as follows:

Tip box will contain all of the applications installed in the phone market, the user selects a corresponding application market and then jump to the details of the interface, if the current application is not in this market shelves "can not find the interface" appears.

Specifies the application market Typically, this requires the user to know the phone installed in the application market, the query as follows:

_getInstallMarket() async {
  List<String> marketList = await FlutterUpgrade.getInstallMarket();
}

Plug-built applications commonly used in China market, including millet, Meizu, vivo, oppo, Huawei, zte, 360 assistants, application treasure, pp assistant, pea pods, if you need to detect other application markets, for example google play, just add googl play package name to:

_getInstallMarket() async {
  List<String> marketList = await FlutterUpgrade.getInstallMarket(marketPackageNames: ['google play 包名']);
}

Method returns the application installed in the phone market, according to market application specified jump installed application market, if you want to specify a built-in application market, you can get information about the built-in application market, according to the package name:

AppMarketInfo _marketInfo = AppMarket.getBuildInMarket(packageName);

Huawei specified application market:

AppUpgrade.appUpgrade(
  context,
  _checkAppInfo(),
  iosAppId: 'id88888888',
  appMarketInfo: AppMarket.huaWei
);

No built-in application designated market as follows:

AppUpgrade.appUpgrade(
  context,
  _checkAppInfo(),
  iosAppId: 'id88888888',
  appMarketInfo: AppMarketInfo(
    '应用市场名称(选填)','应用市场包名','应用市场类名'
  ),
);

Tip box style customization

If the default upgrade prompt box does not meet your needs, you can customize your upgrade prompt box.

title and text styling upgrades:

AppUpgrade.appUpgrade(context, _checkAppInfo(),
    titleStyle: TextStyle(fontSize: 30),
    contentStyle: TextStyle(fontSize: 18),
    ...
)

By titleStyleand contentStyleset its style, you can set the font size, color, bold, and so on.

Settings "Cancel" and "Upgrade button" text and style:

AppUpgrade.appUpgrade(context, _checkAppInfo(),
    cancelText: '以后再说',
    cancelTextStyle: TextStyle(color: Colors.grey),
    okText: '马上升级',
    okTextStyle: TextStyle(color: Colors.red),
    ...
)

Default "Cancel" button text is "later" default "Upgrade" button text is "immediate experience."

Set to "upgrade" the background color of the button, you need two colors, two colors linear gradient from left to right, if you want to set a solid color, just 2 colors can be set to the same color, the default color system primaryColor:

AppUpgrade.appUpgrade(context, _checkAppInfo(),
    okBackgroundColors: [Colors.blue, Colors.lightBlue],
    ...
)

Set the color of the progress bar:

AppUpgrade.appUpgrade(context, _checkAppInfo(),
    progressBarColor: Colors.lightBlue.withOpacity(.4),
    ...
)

Set Upgrade radius balloon, the default is 20:

AppUpgrade.appUpgrade(context, _checkAppInfo(),
    borderRadius: 15,
    ...
)

For environmental reasons, the current source code also can not be published on github and pub, open source will be follow-up, of course, I can focus on the public number, reply "flutter upgrade" to get the source code.

Welcome to the Flutter micro letter exchange group (micro letter: laomengit), learn together and progress together, live in front of more than struggling, as well as poetry and "distant."

Personally, I very much hope that you are concerned about the public number, there are a variety of benefits waiting for you, oh.

Guess you like

Origin www.cnblogs.com/mengqd/p/12520036.html