搜尋套件、儲存庫與 APP 分類

套件詳情v3.0.0

flutter_xupdate

XUpdate(Android 版本更新庫)的 Flutter 插件。

Android
近 30 天下載
153
喜歡數
83
Pub 分數
150

安裝套件

flutter pub add flutter_xupdate

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

flutter_xupdate 是一個 Flutter 插件,整合了 XUpdate,這是一個專為 Android 設計的應用程式更新管理庫。它能在 Android 裝置上實現無縫的應用內更新功能,支援靜默背景更新與使用者觸發的更新提示。此外,該插件簡化了檢查新版本、下載更新及安裝更新的流程,無需完全重啟應用程式。其設計目標是透過減少更新時的干擾來提升使用者體驗。

適用情境

  • 應用內更新通知
  • 靜默後台更新
  • 手動更新觸發
  • 版本相容性檢查
  • 更新進度追蹤

主要特色

  • 僅支援 Android
  • 後台更新下載
  • 可自定義的更新對話框
  • 進度監控
  • 與 XUpdate 庫的整合

適合對象

  • 面向Android的Flutter應用
  • 需要頻繁更新的應用
  • 使用 XUpdate 的開發者
  • 需要輕量級更新邏輯的項目

使用建議

  • 僅限 Android 平台
  • 需要手動設定更新伺服器
  • 不支援 iOS
  • 取決於 XUpdate 後端設定
  • 可能需要自定義UI調整

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_xupdate

Version Build Status Issue Star

A Flutter plugin for XUpdate -- Android Update Library。See the use Chinese Document for details。

About me

WeChat public number juejin zhihu CSDN jianshu segmentfault bilibili toutiao
我的Android开源之旅 Click me Click me Click me Click me Click me Click me Click me

Video tutorial

How to use flutter_xupdate

Stargazers over time

Stargazers over time

Getting Started

You should ensure that you add the flutter_xupdate as a dependency in your flutter project.

// pub 集成
dependencies:
  flutter_xupdate: ^3.0.0

//github  集成
dependencies:
  flutter_xupdate:
    git:
      url: git://github.com/xuexiangjys/flutter_xupdate.git
      ref: master

UseCase

Initialization
  ///初始化
   void initXUpdate() {
     if (Platform.isAndroid) {
       FlutterXUpdate.init(
         ///是否输出日志
         debug: true,
         ///是否使用post请求
         isPost: false,
         ///post请求是否是上传json
         isPostJson: false,
         ///请求响应超时时间
         timeout: 25000,
         ///是否开启自动模式
         isWifiOnly: false,
         ///是否开启自动模式
         isAutoMode: false,
         ///需要设置的公共参数
         supportSilentInstall: false,
         ///在下载过程中,如果点击了取消的话,是否弹出切换下载方式的重试提示弹窗
         enableRetry: false
       ).then((value) {
         updateMessage("初始化成功: $value");
       }).catchError((error) {
         print(error);
       });

       FlutterXUpdate.setErrorHandler(
           onUpdateError: (Map<String, dynamic> message) async {
         print(message);
         setState(() {
           _message = "$message";
         });
       });
     } else {
       updateMessage("ios暂不支持XUpdate更新");
     }
   }

JSON Format
{
  "Code": 0, //0代表请求成功,非0代表失败
  "Msg": "", //请求出错的信息
  "UpdateStatus": 1, //0代表不更新,1代表有版本更新,不需要强制升级,2代表有版本更新,需要强制升级
  "VersionCode": 3,
  "VersionName": "1.0.2",
  "ModifyContent": "1、优化api接口。\r\n2、添加使用demo演示。\r\n3、新增自定义更新服务API接口。\r\n4、优化更新提示界面。",
  "DownloadUrl": "https://raw.githubusercontent.com/xuexiangjys/XUpdate/master/apk/xupdate_demo_1.0.2.apk",
  "ApkSize": 2048
  "ApkMd5": "..."  //md5值没有的话,就无法保证apk是否完整,每次都会重新下载。框架默认使用的是md5加密。
}
CheckUpdate
  ///默认App更新
  void checkUpdateDefault() {
    FlutterXUpdate.checkUpdate(url: _updateUrl);
  }

  ///默认App更新 + 支持后台更新
  void checkUpdateSupportBackground() {
    FlutterXUpdate.checkUpdate(url: _updateUrl, supportBackgroundUpdate: true);
  }

  ///调整宽高比
  void checkUpdateRatio() {
    FlutterXUpdate.checkUpdate(url: _updateUrl, widthRatio: 0.6);
  }

  ///强制更新
  void checkUpdateForce() {
    FlutterXUpdate.checkUpdate(url: mUpdateUrl2);
  }

  ///自动模式, 如果需要完全无人干预,自动更新,需要root权限【静默安装需要】
  void checkUpdateAutoMode() {
    FlutterXUpdate.checkUpdate(url: _updateUrl, isAutoMode: true);
  }

  ///下载时点击取消允许切换下载方式
  void enableChangeDownLoadType() {
    FlutterXUpdate.checkUpdate(
      url: _updateUrl,
      overrideGlobalRetryStrategy: true,
      enableRetry: true,
      retryContent: "Github下载速度太慢了,是否考虑切换蒲公英下载?",
      retryUrl: "https://www.pgyer.com/flutter_learn");
  }
Custom JSON Format

1.Setting up a custom update parser

FlutterXUpdate.setCustomParseHandler(onUpdateParse: (String json) async {
//Here is the custom JSON parsing
return customParseJson(json);
});

///Resolve the custom JSON content to the UpdateEntity entity class
UpdateEntity customParseJson(String json) {
  AppInfo appInfo = AppInfo.fromJson(json);
  return UpdateEntity(
      hasUpdate: appInfo.hasUpdate,
      isIgnorable: appInfo.isIgnorable,
      versionCode: appInfo.versionCode,
      versionName: appInfo.versionName,
      updateContent: appInfo.updateLog,
      downloadUrl: appInfo.apkUrl,
      apkSize: appInfo.apkSize);
}

2.Set the parameter isCustomParse to true

FlutterXUpdate.checkUpdate(url: _updateUrl3, isCustomParse: true);
Update By UpdateEntity Directly
///直接传入UpdateEntity进行更新提示
void checkUpdate8() {
    FlutterXUpdate.updateByInfo(updateEntity: customParseJson(_customJson));
}
Custom Update Prompt Style

Currently, only theme color and top picture customization are supported!

1.Configure top picture, Path: android/app/src/main/res/values/drawable, For example:

2.Set the parameter themeColor 、 topImageRes and buttonTextColor

///自定义更新弹窗样式
void customPromptDialog() {
    FlutterXUpdate.checkUpdate(url: _updateUrl, themeColor: '#FFFFAC5D', topImageRes: 'bg_update_top', buttonTextColor: '#FFFFFFFF');
}

【Note】: When you use the command flutter build apk to make a release package, If you use the topImageRes property, you must configure shrinkResources to false, otherwise the pop-up window will display an exception!

Property value

Initialization
Name Type Default Description
debug bool false Whether Output log
isPost bool false Whether use post request
isPostJson bool false Whether post request upload json format
timeout int 20000(ms) Request response timeout
isWifiOnly bool true Whether update only under WiFi
isAutoMode bool false Whether to turn on automatic mode
supportSilentInstall bool false Whether to support silent installation requires that the device has root permission
enableRetry bool false In the process of downloading, if you click Cancel, whether the pop-up window for retrying to switch the download mode will pop up
retryContent String '' Try the prompt content of the prompt pop-up window again
retryUrl String '' Retrying prompt pop-up URL to jump after clicking
params Map / Public parameters to be set
CheckUpdate
Name Type Default Description
url String / URL of version check
params Map / Parameters
supportBackgroundUpdate bool false Whether to support background updates
isAutoMode bool false Whether to turn on automatic mode
isCustomParse bool false Is it a custom resolution protocol
themeColor String '' Apply pop-up theme color
topImageRes String '' The name of the top picture resource in the pop-up window
buttonTextColor String '' The color of the button text
widthRatio double / Proportion of version update Prompter width to screen
heightRatio double / Proportion of version update Prompter height to screen
overrideGlobalRetryStrategy bool false Whether to override the global retry policy
enableRetry bool false In the process of downloading, if you click Cancel, whether the pop-up window for retrying to switch the download mode will pop up
retryContent String '' Try the prompt content of the prompt pop-up window again
retryUrl String '' Retrying prompt pop-up URL to jump after clicking

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。