You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
2.0 KiB
65 lines
2.0 KiB
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
class PermissionTool {
|
|
static Future<bool> haveCameraPermission() async {
|
|
Map<PermissionGroup, PermissionStatus> permissions =
|
|
await PermissionHandler().requestPermissions([PermissionGroup.camera]);
|
|
if (permissions[PermissionGroup.camera] == PermissionStatus.granted) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static Future<bool> havePhotoPermission() async {
|
|
Map<PermissionGroup, PermissionStatus> permissions =
|
|
await PermissionHandler().requestPermissions([PermissionGroup.photos]);
|
|
if (permissions[PermissionGroup.photos] == PermissionStatus.granted) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static Future<bool> haveAudioPermission() async {
|
|
Map<PermissionGroup, PermissionStatus> permissions =
|
|
await PermissionHandler()
|
|
.requestPermissions([PermissionGroup.microphone]);
|
|
if (permissions[PermissionGroup.microphone] == PermissionStatus.granted) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static showOpenPermissionDialog(BuildContext context, String message,
|
|
{Function open}) {
|
|
showCupertinoDialog<int>(
|
|
context: context,
|
|
builder: (context) {
|
|
return CupertinoAlertDialog(
|
|
title: Text("权限"),
|
|
content: Text(message),
|
|
actions: <Widget>[
|
|
CupertinoDialogAction(
|
|
child: Text("去开启"),
|
|
onPressed: () async {
|
|
if (open != null) {
|
|
open();
|
|
} else {
|
|
bool isOpened = await PermissionHandler().openAppSettings();
|
|
}
|
|
},
|
|
),
|
|
CupertinoDialogAction(
|
|
child: Text("取消"),
|
|
onPressed: () {},
|
|
),
|
|
],
|
|
);
|
|
});
|
|
}
|
|
}
|