flutter 更新apk
创始人
2024-11-14 13:35:08
0
import 'package:path_provider/path_provider.dart';   //app_installer: ^1.0.0 import 'package:app_installer/app_installer.dart';    //path_provider   //查询是否更新   Future ifUpdate(BuildContext buildContext) async {     String jsonFlag = await LocalStorage.get("apkJson");     var s = jsonFlag;     var dio = Dio();     final response = await dio.get(s);     print(response.data);     if(response.data != null){       setState(() {        });       apkJson = response.data;   //json格式{"version":"3.0.1","outputFile":"http://192.168.200.201/test/news.apk","versionName":"ydhl"}     }     PackageInfo packageInfo = await PackageInfo.fromPlatform();     //如果你设置的版本号 于你本机上的App的版本号 不一致 弹出下载框     if (apkJson["version"] != "packageInfo.version") {       print(packageInfo.version);       Msg.dlg(context: context,title: "版本不是最新版,请确定是否更新").then((value)=>{         if(value == ""){           _installApk(apkJson["outputFile"])           // download2()         }       });     }else{       toast("已是最新版");     }   }
/// 下载安卓更新包   Future downloadAndroid(String url) async {     /// 创建存储文件     Directory storageDir = await getExternalStorageDirectory();     String storagePath = storageDir.path;     final directory = await getTemporaryDirectory();     File file = new File("${storageDir.path}/ydhl.apk");      if (!file.existsSync()) {       file.createSync();     }     try {       /// 发起下载请求        Response response = await Dio().download(url,file.path,           options: Options(             followRedirects: false,           ),onProgress: (int count, int total){             if (total != -1) {               //更新界面进度               _value = count / total;               print("------"+_value.toString());               setState(() {                 _value =_value;               });             }           });       // file.writeAsBytesSync(response.data);       return file;     } catch (e) {       showError("下载失败");       debugPrint(e.toString());       setState(() {        });     }   }
/// 安装apk   Future _installApk(String url) async {     File _apkFile = await downloadAndroid(url);     String _apkFilePath = _apkFile.path;      if (_apkFilePath.isEmpty) {       print("make sure the apk file is set");       return;     }     AppInstaller.installApk(_apkFilePath)         .then((ell){       toast("下载成功");     }).catchError((e){       showError("install apk error: $e");     });   }

 更新界面

与界面都在stack中

Visibility(           visible: (_value*100).toInt() != 0 && (_value*100).toInt() != 100,           child: Stack(             children: [               Container(                 height: double.infinity,                 width: double.infinity,                 color: Colors.black12,               ),               Center(                 child: Column(                   mainAxisAlignment: MainAxisAlignment.center,                   crossAxisAlignment: CrossAxisAlignment.center,                   children: [                     Container(                       child: Text("下载中...",style: TextStyle(                         color: Colors.blue,                           decoration: TextDecoration.none                       ),),                     ),                     SizedBox(height: 10,),                     SizedBox(                       height: 20,                       width: 300,                       child: ClipRRect(                         borderRadius: const BorderRadius.all(Radius.circular(100)),                         child: LinearProgressIndicator(                           value: _value,                           backgroundColor: const Color(0xFF7E7F88).withOpacity(0.15),                           valueColor: const AlwaysStoppedAnimation(Colors.green),                         ),                       ),                     ),                   ],                 ),               ),             ],           ),         ),

相关内容

热门资讯

tv十os系统和安卓,两大智能... 你有没有发现,现在手机的世界里,两大操作系统——TV OS系统和安卓,就像是一对好基友,各有各的精彩...
一分钟了解“微信牛牛房卡链接哪... 九酷大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:86909166许多玩家在游戏中会购买房卡来...
头条推荐!斗牛房间怎么创建的王... 头条推荐!斗牛房间怎么创建的王者互娱/微信链接房卡销售购买王者互娱是一款非常受欢迎的游戏,咨询房/卡...
ia攻略/牛牛房卡游戏代理火神... ia攻略/牛牛房卡游戏代理火神大厅/微信链接房卡从哪里购买Sa9Ix苹果iPhone 17手机即将进...
头条推荐!牛牛房卡批发平台光明... 您好!微信光明联盟大厅链接获取房卡可以通过以下几种方式购买: 1.微信渠道:(光明联盟)大厅介绍:...
微信上玩炸金花冲房卡联系方式/... 微信炸金花是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:15984933许多玩家在游戏中会购买房卡...
推荐一款!金花房卡出售玉兔大厅... 玉兔大厅房卡更多详情添加微:33549083、 2、在商城页面中选择房卡选项。 3、根...
头条推荐!金花房卡批发价山竹众... 微信游戏中心:山竹众娱房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
IA解析/如何购买金花房卡西游... 您好!微信西游联盟大厅链接获取房卡可以通过以下几种方式购买: 1.微信渠道:(西游联盟)大厅介绍:...
终于找到“在哪里买炸金花房卡哪... 新九天是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:160470940许多玩家在游戏中会购买房卡来...
ia攻略/金花房卡批发价卡贝大... 卡贝大厅/新上游房卡更多详情添加微:33549083、 2、在商城页面中选择房卡选项。 ...
正规平台有哪些,金花房卡代理零... 正规平台有哪些,金花房卡代理零售龙马大厅/怎么充值获取房卡龙马大厅是一款非常受欢迎的游戏,咨询房/卡...
ia攻略/游戏微信牛牛房卡玄灵... 玄灵大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:332900...
牛牛金花房卡链接在哪买/如何创... 牛牛是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:44346008许多玩家在游戏中会购买房卡来享受...
重大通报,怎么买斗牛房卡新老夫... 您好!微信新老夫子大厅链接获取房卡可以通过以下几种方式购买: 1.微信渠道:(新老夫子)大厅介绍:...
正版授权!牛牛房卡游戏代理青龙... 青龙大厅房卡更多详情添加微:33549083、 2、在商城页面中选择房卡选项。 3、根...
vivo升级安卓6.0系统,畅... 你知道吗?最近vivo手机界可是炸开了锅,因为它们家的新款手机要升级安卓6.0系统啦!这可不是一个小...
头条推荐!金花房卡是正规的卡贝... 头条推荐!金花房卡是正规的卡贝大厅/新上游/房卡购买批发价格卡贝大厅/新上游是一款非常受欢迎的游戏,...
IA解析/斗牛房卡充值天神联盟... 微信游戏中心:天神联盟房卡在哪里买打开微信,添加客服微信【88355042】,进入游戏中心或相关小程...
正规平台有哪些,微信金花房卡怎... 芝麻大厅是一款非常受欢迎的棋牌游戏,咨询房/卡添加微信:【3329006910】或QQ:332900...