2个权限请求接连出现?
2 permission requests appear one after another?
我的代码应该一个接一个地请求两个权限,但有些代码如何一个接一个地显示 2 个权限请求。
我该怎么做才能解决这个问题?
Future<void> checkContactPermission() async {
var status = await Permission.contacts.status;
if (!status.isGranted) {
PermissionStatus permissionStatus = await Permission.contacts.request();
if (status.isDenied) {
PermissionStatus permissionStatus = await Permission.contacts.request();
}
}
if (status.isGranted) {
var contacts = await ContactsService.getContacts(withThumbnails: false);
var list = contacts;
list.shuffle();
var FamilyMember = (list.first.phones?.first.value);
await FlutterPhoneDirectCaller.callNumber('$FamilyMember');
}
}
您正在检查过期状态
if (status.isDenied) {
PermissionStatus permissionStatus = await Permission.contacts.request();
}
刷新状态再使用检查
Future<void> checkContactPermission() async {
var status = await Permission.contacts.status;
if (!status.isGranted) {
PermissionStatus permissionStatus = await Permission.contacts.request();
status = await Permission.contacts.status;
if (status.isDenied) {
PermissionStatus permissionStatus = await Permission.contacts.request();
}
}
if (status.isGranted) {
var contacts = await ContactsService.getContacts(withThumbnails: false);
var list = contacts;
list.shuffle();
var FamilyMember = (list.first.phones?.first.value);
await FlutterPhoneDirectCaller.callNumber('$FamilyMember');
}
}
或使用来自
的结果状态
PermissionStatus permissionStatus = await Permission.contacts.request();
我的代码应该一个接一个地请求两个权限,但有些代码如何一个接一个地显示 2 个权限请求。
我该怎么做才能解决这个问题?
Future<void> checkContactPermission() async {
var status = await Permission.contacts.status;
if (!status.isGranted) {
PermissionStatus permissionStatus = await Permission.contacts.request();
if (status.isDenied) {
PermissionStatus permissionStatus = await Permission.contacts.request();
}
}
if (status.isGranted) {
var contacts = await ContactsService.getContacts(withThumbnails: false);
var list = contacts;
list.shuffle();
var FamilyMember = (list.first.phones?.first.value);
await FlutterPhoneDirectCaller.callNumber('$FamilyMember');
}
}
您正在检查过期状态
if (status.isDenied) {
PermissionStatus permissionStatus = await Permission.contacts.request();
}
刷新状态再使用检查
Future<void> checkContactPermission() async {
var status = await Permission.contacts.status;
if (!status.isGranted) {
PermissionStatus permissionStatus = await Permission.contacts.request();
status = await Permission.contacts.status;
if (status.isDenied) {
PermissionStatus permissionStatus = await Permission.contacts.request();
}
}
if (status.isGranted) {
var contacts = await ContactsService.getContacts(withThumbnails: false);
var list = contacts;
list.shuffle();
var FamilyMember = (list.first.phones?.first.value);
await FlutterPhoneDirectCaller.callNumber('$FamilyMember');
}
}
或使用来自
的结果状态PermissionStatus permissionStatus = await Permission.contacts.request();