王亚玲 2 years ago
parent 8df8d13925
commit 0f4792bfb2

@ -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 = <AndroidStoreName>[];
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 = <AndroidStoreName>[];
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);

Loading…
Cancel
Save