request static method
申请权限
Implementation
static Future<bool> request({
required Permission permission,
String? title,
String? confirmText,
required String message,
required String error,
double? width,
}) async {
if (await permission.isGranted) {
return true;
}
Completer<bool> completer = Completer<bool>();
DialogX.to.showPromptDialog(
icon: DialogIcon.warn,
title: title ?? '授权确认',
message: message,
barrierDismissible: false,
confirmText: confirmText ?? '确认授权',
width: width,
onConfirm: () async {
var status = await permission.request();
if (status.isGranted) {
completer.complete(true);
} else {
completer.complete(false);
}
},
onCancel: () {
completer.complete(false);
},
);
if (await completer.future) {
return true;
} else {
showError(error);
return false;
}
}