no message

This commit is contained in:
1147192855@qq.com 2024-05-13 18:42:41 +08:00
parent e727cb3d20
commit 309c708847
3 changed files with 146 additions and 37 deletions

View File

@ -11,13 +11,18 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:install_plugin/install_plugin.dart';
import 'package:marking_app/provider/upgrade_provider.dart';
import 'package:marking_app/utils/app_upgrade/model/UpdateAppEvent.dart';
import 'package:marking_app/utils/index.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:path_provider/path_provider.dart';
import 'package:app_installer/app_installer.dart';
import 'package:url_launcher/url_launcher.dart';
import 'UpgradePermission.dart';
class DownloadApk {
///
@ -58,26 +63,43 @@ class DownloadApk {
debugPrint('make sure the apk file is set');
return false;
}
Map<Permission, PermissionStatus> statuses = await [Permission.storage].request();
if (statuses[Permission.storage]!.isGranted) {
// String? result = await InstallPlugin.installApk(_apkFilePath, appId: event.packageName).catchError((error) {
// debugPrint('install apk error: $error');
// });
// debugPrint('install apk $result');
// ToastUtils.getFluttertoast(context: context, msg: 'install apk $result');
try {
// InstallPlugin.install(filePathOrUrlString)com.example.marking_app
await AppInstaller.installApk(_apkFilePath);
// var result = await InstallPlugin.installApk(_apkFilePath, appId: event.packageName);
// print('这是是执行安装的程序:' + jsonEncode(result));
// if (!(result?['isSuccess'] ?? false)) {}
// Restadget.restartApp(context); // APP
await showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("未知应用安装权限提示"),
content: const Text("更新时若出现需要同意安装未知应用权限时,请同意"),
actions: [
MaterialButton(
color: Theme.of(context).primaryColor,
child: const Text("我已知晓", style: TextStyle(color: Colors.white)),
onPressed: () => Navigator.of(context).pop(),
),
],
);
},
);
await AppInstaller.installApk(_apkFilePath); // APK
// 2
await setTimeOut(5000, () async {
try {
//
// await SystemNavigator.pop(); // 退APP
var options = ['应用市场更新APP', '浏览器下载并安装APP'];
var uri = Uri.parse('market://details?id=com.example.marking_app'); // URI
if (!await canLaunchUrl(uri)) options.removeAt(0); //
String? option = await UpgradePermission.showCustomModalBottomSheet(context, options);
if (option == '应用市场更新APP') await launchUrl(uri);
if (option == '浏览器下载并安装APP') await launchUrl(Uri.parse(event.link));
} catch (e) {}
});
print('安装执行完成了..............0.0');
} catch (e) {
print('安装进入报错....');
print(e);
}
}
return false;
}

View File

@ -177,10 +177,9 @@ class DownloadButton extends ConsumerWidget {
onPressed: () => easyThrottle('DownloadButton_App_Upgrade', () async {
if (deviceInfo == "android" && updateAppEvent.equipment == Equipment.android) {
//
bool flag = await UpgradePermission(updateAppEvent.deviceInfo).checkPermission(context);
bool flag = await UpgradePermission(updateAppEvent.deviceInfo).checkPermission(context, updateAppEvent);
if (flag) {
flag = await DownloadApk.installApk(context, updateAppEvent, ref);
if (!flag) {
print('执行到了重置更新按钮的地方....');
ref.read(upgradeProvider.notifier).clean(); //
@ -190,8 +189,6 @@ class DownloadButton extends ConsumerWidget {
}
return;
}
//
await toLaunch(updateAppEvent);
// await FlutterClipboard.copy(updateAppEvent.link);
// setTimeOut(1000, () => ToastUtils.showInfo('下载链接已经复制到设备,可前往浏览器下载安装'));
} else if (deviceInfo == "ios" && updateAppEvent.equipment == Equipment.ios) {

View File

@ -6,23 +6,50 @@
* @LastEditors: wangyang 1147192855@qq.com
* @LastEditTime: 2022-08-01 14:08:57
*/
import 'package:app_installer/app_installer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:marking_app/utils/index.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';
import 'model/UpdateAppEvent.dart';
class UpgradePermission {
final String _flatform;
const UpgradePermission(this._flatform);
///
Future<bool> checkPermission(BuildContext context) async {
/// noExecutions
Future<bool> checkPermission(BuildContext context, UpdateAppEvent updateAppEvent, [int? noExecutions]) async {
noExecutions ??= 1;
if (_flatform != 'android') return true; //
var status = await Permission.storage.request();
if (status.isGranted) return true;
if (status.isDenied) {
//
if (noExecutions == 3) {
//
await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: const Text("提示"),
content: const Text("若“拒绝并不再提示”或“没有弹出权限询问对话框”,再次点击同意按钮出现其他更新方式。"),
actions: [
MaterialButton(
color: Theme.of(context).primaryColor,
child: const Text("确定", style: TextStyle(color: Colors.white)),
onPressed: () => Navigator.of(context).pop(),
)
],
);
},
);
}
await showDialog<bool>(
context: context,
barrierDismissible: false,
@ -41,17 +68,18 @@ class UpgradePermission {
},
);
if (isPad()) {
// APP权限设置页面
await openAppSettings();
return false;
}
// if (isPad()) {
// // APP权限设置页面
// await openAppSettings();
// return false;
// }
return checkPermission(context);
if (noExecutions <= 2) return checkPermission(context, updateAppEvent, ++noExecutions);
// 3
}
//
await showDialog(
bool? res = await showDialog<bool>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
@ -61,20 +89,82 @@ class UpgradePermission {
actions: [
MaterialButton(
color: Colors.green.shade900,
child: const Text("退出APP", style: TextStyle(color: Colors.white)),
child: const Text("其它方式更新", style: TextStyle(color: Colors.white)),
onPressed: () => Navigator.of(context).pop(false),
),
MaterialButton(
color: Colors.green.shade900,
child: const Text("确定", style: TextStyle(color: Colors.white)),
color: Theme.of(context).primaryColor,
child: const Text("前往设置", style: TextStyle(color: Colors.white)),
onPressed: () => Navigator.of(context).pop(true),
),
],
);
},
);
if (res == null || !res) {
//
// await SystemNavigator.pop(); // 退APP
var options = ['应用市场更新APP', '浏览器下载并安装APP'];
var uri = Uri.parse('market://details?id=com.example.marking_app'); // URI
// if (!await canLaunchUrl(uri)) options.removeAt(0); //
String? option = await showCustomModalBottomSheet(context, options);
if (option == '应用市场更新APP') {
if (await canLaunchUrl(uri))
await launchUrl(uri);
else
await AppInstaller.goStore('com.example.marking_app', 'iOSAppId');
}
if (option == '浏览器下载并安装APP') await launchUrl(Uri.parse(updateAppEvent.link));
} else
await openAppSettings();
return false;
}
//
static Future<String?> showCustomModalBottomSheet(context, List<String> options) async {
return showModalBottomSheet<String>(
backgroundColor: Colors.transparent,
isScrollControlled: true,
context: context,
builder: (BuildContext context) {
return Container(
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0),
),
),
height: MediaQuery.of(context).size.height / 4.0,
child: Column(children: [
SizedBox(
height: 50,
child: Stack(
textDirection: TextDirection.rtl,
children: [
Center(child: Text('选择其它方式更新APP', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16.0))),
IconButton(icon: Icon(Icons.close), onPressed: () => Navigator.of(context).pop()),
],
),
),
Divider(height: 1.0),
Expanded(
child: ListView.builder(
itemCount: options.length,
itemBuilder: (BuildContext context, int index) {
var name = options[index];
return ListTile(
title: Text(name),
trailing: Icon(name.contains('浏览器') ? Icons.browser_updated_outlined : Icons.local_grocery_store_outlined),
onTap: () => Navigator.of(context).pop(name),
);
},
),
),
]),
);
},
);
}
}