flutter 更新app下载安装

刚开始用的OtaUpdate插件,插件内部使用downloadmanager实现的国内有很多机型不支持

思路:不想自己造轮子 使用网上现有插件

一、使用FlutterDownloader下载

二、open_file打开文件自带安装(FlutterDownloader自带打开文件,但不能打开app不知道为啥)

代码:

1、下载监听 

FlutterDownloader.registerCallback((id, status, progress) {
      print(
          'Download task ($id) is in status ($status) and process ($progress)');
      if (status == DownloadTaskStatus.complete) {
        OpenFile.open(_localPath);
        FlutterDownloader.open(taskId: id);
      }
    });

2、下载

final taskId = await FlutterDownloader.enqueue(
  url: url,
  savedDir: _localPath,
  showNotification:
      true, // show download progress in status bar (for Android)
  openFileFromNotification:
      true, // click on notification to open downloaded file (for Android)
);
final tasks = await FlutterDownloader.loadTasks();

你可能感兴趣的:(flutter,flutter爬坑之路)