1 Star 0 Fork 0

Jackchen / flutter_app_upgrade_plus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

flutter_app_upgrade_plus

Flutter App升级工具空安全版本 原作者 https://github.com/781238222/flutter-do/tree/master/flutter_app_upgrade 升级版

添加依赖

1、在pubspec.yaml中加入:

2、执行flutter命令获取包:

flutter pub get`

3、引入

import 'package:flutter_app_upgrade_plus/flutter_app_upgrade.dart';

4、如果你需要支持Android平台,在./android/app/src/main/AndroidManifest.xml文件中配置provider,代码如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.flutter.laomeng.flutter_upgrade_example">
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="flutter_upgrade_example">
				...
        <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.flutter.laomeng.flutter_upgrade_example.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                tools:replace="android:resource"
                android:resource="@xml/file_paths" />
        </provider>
    </application>
</manifest>

注意:provider中authorities的值为当前App的包名,和顶部的package值保持一致。

App升级功能使用介绍

只需在主页的initState方法中调用升级检测方法:

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

_checkAppInfo方法访问后台接口获取是否有新的版本的信息,返回Future<AppUpgradeInfo> 类型,AppUpgradeInfo包含title、升级内容、apk下载url、是否强制升级等版本信息。如果没有新的版本不返回即可。

iosAppId参数用于跳转到app store。

_checkAppInfo()方法通常是访问后台接口,这里直接返回新版本信息,代码如下:

 Future<AppUpgradeInfo> _checkAppInfo() async {
    //这里一般访问网络接口,将返回的数据解析成如下格式
    return Future.delayed(Duration(seconds: 1), () {
      return AppUpgradeInfo(
        title: '新版本V1.1.1',
        contents: [
          '1、支持立体声蓝牙耳机,同时改善配对性能',
          '2、提供屏幕虚拟键盘',
          '3、更简洁更流畅,使用起来更快',
          '4、修复一些软件在使用时自动退出bug',
          '5、新增加了分类查看功能'
        ],
        force: false,
      );
    });
  }

好了,基本的升级功能就完成了,弹出提示框的效果如下:

点击“以后再说”,提示框消失,点击“立即体验”,自动区分不同平台。

访问后台接口获取新版本的信息一般需要当前App的包名和版本,查询方法如下:

await FlutterUpgrade.appInfo

返回的类型是AppInfo

  • versionName:版本号,比如1.0.0。
  • versionCode:Android独有版本号,对应Android build.gradle中的versionCode,ios返回“0”。
  • packageName:包名,对应Android build.gradle中的applicationId,ios的BundleIdentifier。

iOS平台升级

iOS平台直接跳转到app store相关页面,iosAppId一定要设置对,否则app store会找不到应用程序。

Android平台下载apk

Android平台则会判断是否设置了apk下载url,如果设置了则下载apk则直接下载,效果如下:

当下载完成时直接跳转到apk安装引导界面,效果如下:

用户点击允许,出现如下界面:

点击继续安装即可,上面的安装引导界面是系统界面,不同的手机或者不同的Android版本会略有不同。

Android平台跳转应用市场

如果不提供apk下载地址,点击“立即体验”,则会跳转到应用市场,不指定应用市场则会弹出提示框,让用户选择应用市场,效果如下:

提示框内将会包含手机内安装的所有的应用市场,用户选择一个然后跳转到对应应用市场的详情界面,如果当前应用未在此市场上架则会出现“找不到的界面”。

通常情况下会指定应用市场,这就需要知道用户手机内安装的应用市场,查询方法如下:

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

插件内置了国内常用的应用市场,包括小米、魅族、vivo、oppo、华为、zte、360助手、应用宝、pp助手、豌豆荚,如果你需要检测其他的应用市场,比如google play,只需添加googl play的包名即可:

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

方法返回手机安装的应用市场,根据安装的应用市场指定跳转应用市场,如果你要指定内置的应用市场,可以根据包名获取内置的应用市场的相关信息:

AppMarketInfo _marketInfo = AppMarket.getBuildInMarket(packageName);

指定华为应用市场:

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

指定没有内置的应用市场方法如下:

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

用户行为和下载回调

新的版本(1.1.0)新增了取消立即更新回调,用法如下:

AppUpgrade.appUpgrade(
  context,
  _checkAppInfo(),
  cancelText: '以后再说',
  okText: '马上升级',
  iosAppId: 'id88888888',
  appMarketInfo: AppMarket.huaWei,
  onCancel: () {
    print('onCancel');
  },
  onOk: () {
    print('onOk');
  },
  
);

新增的下载进度下载状态变化回调,用法如下:

AppUpgrade.appUpgrade(
  context,
  _checkAppInfo(),
  cancelText: '以后再说',
  okText: '马上升级',
  iosAppId: 'id88888888',
  appMarketInfo: AppMarket.huaWei,
  downloadProgress: (count, total) {
    print('count:$count,total:$total');
  },
  downloadStatusChange: (DownloadStatus status, {dynamic error}) {
    print('status:$status,error:$error');
  },
);

提示框样式定制

如果默认的升级提示框不满足你的需求,那么你可以定制你的升级提示框。

title及升级内容文字样式设置:

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

通过titleStylecontentStyle设置其样式,可以设置字体大小、颜色、粗体等。

设置“取消”和“升级按钮”文本和样式:

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

默认“取消”按钮文本是"以后再说",默认“升级”按钮的文本是“立即体验”。

设置“升级”按钮的背景颜色,需要2种颜色,2种颜色左到右线性渐变,如果想设置纯色,只需将2种颜色设置为同一个颜色即可,默认颜色是系统的primaryColor:

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

设置进度条的颜色:

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

设置升级提示框的圆角半径,默认是20:

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

Flutter App 升级功能流程

应用程序升级功能是App的基础功能之一,如果没有此功能会造成用户无法升级,应用程序的bug或者新功能老用户无法触达,甚至损失这部分用户。

对于应用程序升级功能的重要性就无需赘言了,下面介绍下应用程序升级功能的几种方式,从平台方面来说:

  • IOS平台,应用程序升级功能只能通过跳转到app store进行升级。
  • Android平台,既可以通过跳转到应用市场进行升级,也可以下载apk包升级。

从强制性来说可以分别强制升级和非强制升级:

  • 强制升级:就是用户必须升级才能继续使用App,如果不是非常必要不建议使用如此强硬的方式,会造成用户的反感。
  • 非强制升级就是允许用户点击“取消”,继续使用App。

下面分别介绍IOS和Android升级流程。

IOS升级流程

IOS升级流程如下:

流程说明:

  1. 通常我们会访问后台接口获取是否有新的版本,如果有新的版本则弹出提示框,判断当前版本是否为“强制升级”,如果是则只提供用户一个“升级”的按钮,否则提供用户“升级”和“取消”按钮。
  2. 弹出提示框后用户选择是否升级,如果选择“取消”,提示框消失,如果选择“升级”,跳转到app store进行升级。

Android 升级流程

相比ios的升级过程,Android就稍显复杂了,流程图如下:

流程说明:

  1. 访问后台接口获取是否有新的版本,这里和IOS是一样的,有则弹出升级提示框,判断当前版本是否为“强制升级”,如果是则只提供用户一个“升级”的按钮,否则提供用户“升级”和“取消”按钮。
  2. 弹出提示框后有用户选择是否升级,如果选择“取消”,提示框消失,如果选择“升级”,判断是跳转到应用市场进行升级还是通过下载apk升级。
  3. 如果下载apk升级,则开始下载apk,下载完成后跳转到apk安装引导界面。
  4. 如果跳转到应用市场升级,判断是否指定了应用市场,比如只在华为应用市场上架了,那么此时需要指定跳转到华为应用市场,即使你在很多应用市场都上架了,也应该根据用户手机安装的应用市场指定一个应用市场,让用户选择应用市场不是一个好的体验,而且用户也不知道应该去哪个市场更新,如果用户选择了一个你没有上架的应用市场,那就更尴尬了。
  5. 指定应用市场后直接跳转到指定的应用市场的更新界面。
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

暂无描述 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Dart
1
https://gitee.com/Jack-chendeng/flutter_app_upgrade_plus.git
git@gitee.com:Jack-chendeng/flutter_app_upgrade_plus.git
Jack-chendeng
flutter_app_upgrade_plus
flutter_app_upgrade_plus
main

搜索帮助

53164aa7 5694891 3bd8fe86 5694891