getPermissions function
Future<bool>
getPermissions(
- List<
Permission> permissions, { - required String alert,
- GestureTapCallback? cancelTap,
必须获取通过全部权限
Implementation
Future<bool> getPermissions(List<Permission> permissions,
{required String alert, GestureTapCallback? cancelTap}) async {
if (!isMobile) return true;
Map<Permission, bool> status = {};
for (var element in permissions) {
final isGranted = await element.isGranted;
final isLimited = await element.isLimited;
if (!(isGranted || isLimited)) status.addAll({element: isGranted});
}
if (status.isNotEmpty) {
PermissionPrompt.show(content: alert);
final permissionsStatus = await status.keys.toList().request();
permissionsStatus
.removeWhere((key, value) => value.isGranted || value.isLimited);
pop();
if (permissionsStatus.isNotEmpty) {
final result = await AlertConfirmCancel(
text: alert,
autoClose: false,
confirmTap: () {
pop(true);
},
cancelTap: () {
pop(false);
cancelTap?.call();
}).show();
if (result == true) await openAppSettings();
}
return permissionsStatus.isEmpty;
}
return true;
}