zoukankan      html  css  js  c++  java
  • flutter 应用自动更新

    话不多说直接上代码:

    package_info: ^0.4.0+16
      path_provider: ^1.6.5
      open_file: ^3.0.1
      url_launcher: ^5.4.2
    _update() async {
        if (Platform.isIOS) {
    //      String url =
    //          'itms-apps://itunes.apple.com/cn/app/id414478124?mt=8'; // 这是微信的地址,到时候换成自己的应用的地址
    //      if (await canLaunch(url)) {
    //        await launch(url);
    //      } else {
    //        throw 'Could not launch $url';
    //      }
        } else if (Platform.isAndroid) {
          String url = HttpUtils.VERSION_URL + 'app-release.apk';
          try {
            /// 创建存储文件
            Directory storageDir = await getExternalStorageDirectory();
            String storagePath = storageDir.path;
            File _apkFile = await downloadAndroid(storagePath,url);
            OpenFile.open("${storagePath}/app-release.apk");
          } catch (e) {
            print('${e}');
          }
        }
      }
    
      /// 下载安卓更新包
      Future<File> downloadAndroid(String storagePath,String url) async {
        File file = new File('$storagePath/app-release.apk');
        if (!file.existsSync()) {
          file.createSync();
        }
        try {
          print("-------------333333333333");
          Function tr = throttle((List args){
            print("-----------------------6666");
            int count = args[0];
            int total = args[1];
            double radio = count/total;
            String str = (_progress_val*100).toInt().toString();
            setState(() {
              _progress_val = radio;
              _progress = "下载进度:${str}%";
            });
          }, 500);
          /// 发起下载请求
          Response response = await Dio().get(url,
              onReceiveProgress: (int count,int total){
    //            tr([count,total]);
                double radio = count/total;
                String str = (_progress_val*100).toInt().toString();
                setState(() {
                  _progress_val = radio;
                  _progress = "下载进度:${str}%";
                });
              },
              options: Options(
                responseType: ResponseType.bytes,
                followRedirects: false,
              ));
          file.writeAsBytesSync(response.data);
          return file;
        } catch (e) {
          print(e);
        }
      }
  • 相关阅读:
    python开源项目
    Appscan 10用户安装手册
    20201201-k8s的node节点和独立nginx部署会冲突
    k8s-更换证书(apiserver新添加了VIP)
    20201224-修改pod网段(calico)
    深-宝的一梦
    洛谷-P3383 【模板】线性筛素数
    洛谷-P3913 车的攻击
    洛谷-P1866 编号
    洛谷-P1100 高低位交换
  • 原文地址:https://www.cnblogs.com/Mvloveyouforever/p/12668855.html
Copyright © 2011-2022 走看看