因为windows应用一般大家都是从网上下载的,后期版本肯定会更新,那用flutter开发windows应用,
怎么实现应用内版本更新功能了?可以使用auto_updater库,
这个插件允许 Flutter 桌面 应用自动更新自己 (基于 sparkle 和 winsparkle)
地址如下:
https://github.com/leanflutter/auto_updater
#将此添加到你的软件包的 pubspec.yaml 文件:
dependencies:
  auto_updater: ^0.1.7
dependencies:
  auto_updater:
      url: https://github.com/leanflutter/auto_updater.git
      ref: main

3.1、windows使用需要openssl

运行以下命令:
使用 Chocolatey
choco install openssl

3.2、生成私钥

#运行以下命令:
dart run auto_updater:generate_keys
macOS
准备使用 EdDSA 签名算法进行签名:
A key has been generated and saved in your keychain. Add the `SUPublicEDKey` key to
the Info.plist of each app for which you intend to use Sparkle for distributing
updates. It should appear like this:
    <key>SUPublicEDKey</key>
    <string>pfIShU4dEXqPd5ObYNfDBiQWcXozk7estwzTnF9BamQ=</string>
更改文件 macos/Runner/Info.plist 如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
+	<key>SUPublicEDKey</key>
+	<string>bHaXClrRGMmKoKP/3HJnr/jn2ODTRPAM3VZhhkI9ZvY=</string>
</dict>
</plist>
Windows
准备使用 DSA 签名算法进行签名:
Generated two files:
dsa_priv.pem: your private key. Keep it secret and don't share it!
dsa_pub.pem: public counterpart to include in youe app.
BACK UP YOUR PRIVATE KEY AND KEEP IT SAFE!
If you lose it, your users will be unable to upgrade!
命令将为你生成私钥(dsa_priv.pem)及公钥(dsa_pub.pem),请备份你的私钥并确保其安全,并将公钥作为 Windows 资源添加到项目中。
更改文件 windows/runner/Runner.rc 如下:
+// WinSparkle
+// And verify signature using DSA public key:
+DSAPub      DSAPEM      "../../dsa_pub.pem"

3.3、打包exe

基于flutter_distributor打包,具体使用可以参考如下地址:
https://blog.csdn.net/LuoHuaX/article/details/135695911?spm=1001.2014.3001.5501

3.4、获取签名

macOS
运行以下命令:命令后面的目录和文件名根据你的项目进行修改
dart run auto_updater:sign_update dist/1.1.0+2/auto_updater_example-1.1.0+2-macos.zip
sparkle:edSignature="pbdyPt92pnPkzLfQ7BhS9hbjcV9/ndkzSIlWjFQIUMcaCNbAFO2fzl0tISMNJApG2POTkZY0/kJQ2yZYOSVgAA==" length="13400992"
将获得的新签名更新到 appcast.xml 文件 enclosure 节点的 sparkle:edSignature 属性值。
Windows
运行以下命令:命令后面的目录和文件名根据你的项目进行修改
dart run auto_updater:sign_update dist/1.1.0+2/auto_updater_example-1.1.0+2-windows-setup.exe
sparkle:dsaSignature="MEUCIQCVbVzVID7H3aUzAY5znpi+ySZKznkukV8whlMFzKh66AIgREUGOmvavlcg6hwAwkb2o4IqVE/D56ipIBshIqCH8rk=" length="13400992"
将获得的新签名更新到 appcast.xml 文件 enclosure 节点的 sparkle:dsaSignature 属性值。

3.5、部署更新appcast.xml文件

创建appcast.xml文件,内容如下,将它部署到服务器,还有exe更新程序的下载地址,可以放到云存储上面,比如七牛云,也可以放到服务器上(会占服务器带宽),可以找后端同事帮下忙

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
    <channel>
        <title>auto_updater_example</title>
        <description>Most recent updates to auto_updater_example</description>
        <language>en</language>
            <title>Version 1.1.0</title>
            #发行说明-读取html方式(2选1)
            <sparkle:releaseNotesLink>
                https://your_domain/your_path/release_notes.html
            </sparkle:releaseNotesLink>
            #发行说明-写死方式(2选1)
            <description>
                <![CDATA[
              <li>1、新增XX功能</li>
              <li>2、新增XX功能</li>
            </description>
            <pubDate>Sun, 16 Feb 2022 12:00:00 +0800</pubDate>
            #你更新程序的地址
            <enclosure url="http://wwww.xxx.com/1.1.0+2/auto_updater_example-1.1.0+2-macos.zip"
                       sparkle:edSignature="pbdyPt92pnPkzLfQ7BhS9hbjcV9/ndkzSIlWjFQIUMcaCNbAFO2fzl0tISMNJApG2POTkZY0/kJQ2yZYOSVgAA=="
                       sparkle:version="1.1.0"
                       sparkle:os="macos"
                       length="13400992"
                       type="application/octet-stream" />
        </item>
            <title>Version 1.1.0</title>
            #发行说明-读取html方式(2选1)
            <sparkle:releaseNotesLink>
                https://your_domain/your_path/release_notes.html
            </sparkle:releaseNotesLink>
            #发行说明-写死方式(2选1)
            <description>
                <![CDATA[
              <li>1、新增XX功能</li>
              <li>2、新增XX功能</li>
            </description>
            <pubDate>Sun, 16 Feb 2022 12:00:00 +0800</pubDate>
            #你更新程序的地址
            <enclosure url="http://www.xx.com/1.1.0+2/auto_updater_example-1.1.0+2-windows.exe"
                       sparkle:dsaSignature="MEUCIQCVbVzVID7H3aUzAY5znpi+ySZKznkukV8whlMFzKh66AIgREUGOmvavlcg6hwAwkb2o4IqVE/D56ipIBshIqCH8rk="
                       sparkle:version="1.1.0+2"
                       sparkle:os="windows"
                       length="0"
                       type="application/octet-stream" />
        </item>
    </channel>

3.6、项目更新版本代码

import 'package:auto_updater/auto_updater.dart';
void main() async {
  // 必须加上这一行。
  WidgetsFlutterBinding.ensureInitialized();
  //这段代码不一定要放在main文件,除非你想打开应用就检查更新,也可以放到你点击检查更新的页面
  String feedURL = 'http://www.xx.com/appcast.xml'; //就是你appcast.xml文件部署的地址
  await autoUpdater.setFeedURL(feedURL);
  await autoUpdater.checkForUpdates();
  await autoUpdater.setScheduledCheckInterval(3600);
  runApp(MyApp());

3.7、测试更新

1、先打包一个更新的版本,比如1.0.1+2,然后将程序放到七牛云或者服务器上,获取下载地址,
复制到appcast.xml的<enclosure>标签,还有生成签名,复制到sparkle:dsaSignature标签,
最后将appcast.xml部署到服务器
2、再打包一个老版本,比如1.0.0+1,然后使用
String feedURL = 'http://www.xx.com/appcast.xml'; //就是你appcast.xml文件部署的地址
await autoUpdater.setFeedURL(feedURL);
await autoUpdater.checkForUpdates();
await autoUpdater.setScheduledCheckInterval(3600);
这段代码,进行更新测试,具体效果看下面

3.8、实际效果展示

import 'dart:isolate'; import 'dart:ui'; import 'package:flutter_downloader/flutter_downloader.dart'; import 'package:flutter/material.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:path_provider/path_ 生成Sparkle appcast.xml / delta补丁并自动对其进行签名(实验) git clone https://github.com/typcn/SparkleGen.git git submodule update --init open * .xcodeproj 选择私钥和BinaryDelta可执行文件位置(仅一次,自动保存) 拖放您的“ .app”文件。 单击生成,然后打开“ update_xxx”文件夹 您可以在ViewController.m中设置“发布”操作,与S3 SDK,CDN API或SFTP集成以上传它。 麻省理工学院
文章目录一、前言二、升级PowerShell三、参考链接 由于Flutter更新了几个版本,所以这里也升级一下,之前的版本是1.22.4的Stable版本,现在最新版本是1.22.6。这里采用了flutter upgrade的命令进行升级,但是报了一些错,然后就懒省事,直接又去官网下了一个最新的压缩包进行替换,然后在Android Studio那里出现了SDK不完整的提示…。后面发现1.22.6的SDK竟然比1.22.4的SDK少了一半…。下面记录下升级的步骤 二、升级PowerShell Flutter 与 iOS 混合项目初探 Flutter混合开发(二):iOS项目集成Flutter模块详细指南 Flutter 开发 (1)iOS 下超详细集成 Flutter  Flutter中文网 在macOS上搭建Flutter开发环境 1.下载flutter SDK https://flutter.cn/docs/deve...........................
根据引用和引用可以得知,Flutter已经为Windows应用开发做好了准备,并且在Windows上推出了Flutter的支持。FlutterWindows版本结合了Dart框架和C引擎,通过嵌入层与Windows进行通信,并将UI绘制到屏幕上。这意味着开发者现在可以使用Flutter来构建和上架Windows应用程序。Flutter提供了跨平台的开发能力,使开发者能够同时为Android、iOS和Windows等多个平台开发应用程序。因此,如果开发者希望上架Windows应用,他们可以使用Flutter来构建应用,并通过Windows商店或其他途径将其上架。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Flutter稳定支持Windows,开发者做好准备了吗?](https://blog.csdn.net/weixin_39787030/article/details/122808516)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Flutter 稳定版支持 Windows,开发者还学的动吗?](https://blog.csdn.net/weixin_38754349/article/details/122994720)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]