From 0f4792bfb2a5a5b7bf3de8772c083af295cf4147 Mon Sep 17 00:00:00 2001 From: wyl2022 <2373073266@qq.com> Date: Fri, 24 Jun 2022 17:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/aku_app_upgrade.dart | 182 +++++++++++++++++++++++++++++---------- 1 file changed, 135 insertions(+), 47 deletions(-) diff --git a/lib/aku_app_upgrade.dart b/lib/aku_app_upgrade.dart index c7e8e26..3bdc773 100644 --- a/lib/aku_app_upgrade.dart +++ b/lib/aku_app_upgrade.dart @@ -8,6 +8,8 @@ import 'package:package_info_plus/package_info_plus.dart'; import 'package:dio/dio.dart'; import 'package:r_upgrade/r_upgrade.dart'; +const apkLink = 'https://saas.kaidalai.cn/resource/appPackage/app.apk'; + enum ForceUpgrade { force(1), unForce(2); @@ -185,66 +187,152 @@ class AppUpgrade { child: MaterialButton( onPressed: () async { if (Platform.isAndroid) { - var stores = await RUpgrade.androidStores; - if (stores == null || stores.isEmpty) { - onLaunchFail?.call(); - return; - } - var storeEMs = []; - for (var element in stores) { - var re = AndroidStoreName.getValue( - element.packageName); - if (re != AndroidStoreName.empty) { - storeEMs.add(re); - } - } - AndroidStoreName? selectStore; - selectStore = await showModalBottomSheet( + showModalBottomSheet( isDismissible: false, context: context, builder: (context) { - return Center( - child: Column( + return Container( + child: + Column( children: [ const SizedBox(height: 20), - const Text('选择应用商店'), - Expanded( - child: ListView.separated( - itemBuilder: (context, index) { - return GestureDetector( - onTap: () { - Navigator.pop(context, - storeEMs[index]); + const Text('选择下载途径',style: TextStyle(fontSize: 24),), + const Divider(), + GestureDetector( + onTap: () async{ + await RUpgrade.upgrade(apkLink); }, child: Padding( - padding: - const EdgeInsets.all( - 32.0), - child: Center( - child: Text( - storeEMs[index] - .name), - ), + padding: + const EdgeInsets.only(top: 0), + child: + Column(children: [ + const Divider(), + SizedBox( + height: 20, + child:Text( + '直接下载',style:const TextStyle(fontSize: 14,),), + ), + + ],) + ), - ); - }, - separatorBuilder: - (context, index) { - return const SizedBox( - height: 10, - ); - }, - itemCount: storeEMs.length), + ), + const Divider(), + GestureDetector( + onTap: () async{ + var stores = await RUpgrade.androidStores; + if (stores == null || stores.isEmpty) { + onLaunchFail?.call(); + return; + } + var storeEMs = []; + for (var element in stores) { + var re = AndroidStoreName.getValue( + element.packageName); + if (re != AndroidStoreName.empty) { + storeEMs.add(re); + } + } + AndroidStoreName? selectStore; + selectStore = await showModalBottomSheet( + isDismissible: false, + context: context, + builder: (context) { + return Container( + // decoration: const BoxDecoration(gradient: LinearGradient( + // begin: Alignment.topCenter, + // end: Alignment.bottomCenter, + // stops: [ + // 0, + // 0.7 + // ], + // colors: [ + // Color(0x33FBE541), + // Colors.white, + // ]), + // // borderRadius: BorderRadius.only( + // // topLeft: Radius.circular(25.0), + // // topRight: Radius.circular(25.0)) + // ), + child: + Column( + children: [ + const SizedBox(height: 20), + const Text('选择应用商店',style: TextStyle(fontSize: 24),), + Expanded( + child: ListView.separated( + itemBuilder: (context, index) { + return GestureDetector( + onTap: () { + Navigator.pop(context, + storeEMs[index]); + }, + child: Padding( + padding: + const EdgeInsets.only(top: 0), + child: + Column(children: [ + const Divider(), + SizedBox( + height: 20, + child:Text( + storeEMs[index] + .name,style:const TextStyle(fontSize: 14,),), + ), + + ],) + + ), + ); + }, + separatorBuilder: + (context, index) { + return const SizedBox( + height: 10, + ); + }, + itemCount: storeEMs.length), + ), + GestureDetector(onTap: (){ + Navigator.pop(context); + },child: const Text('取消',style: TextStyle(fontSize: 20),),) + ], + ), + ); + }); + await Future.delayed(Duration.zero, () async { + if (selectStore == null) return; + }); + await RUpgrade.upgradeFromAndroidStore( + selectStore!.getAndroidStore); + }, + child: Padding( + padding: + const EdgeInsets.only(top: 0), + child: + Column(children: [ + const Divider(), + SizedBox( + height: 20, + child:Text( + '应用市场',style:const TextStyle(fontSize: 14,),), + ), + + ],) + + ), ), + + + + ], ), ); }); - await Future.delayed(Duration.zero, () async { - if (selectStore == null) return; - }); - await RUpgrade.upgradeFromAndroidStore( - selectStore!.getAndroidStore); + + } else if (Platform.isIOS) { await RUpgrade.upgradeFromAppStore( packageInfo.packageName);