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.

94 lines
2.7 KiB

2 years ago
import 'package:flutter/cupertino.dart';
2 years ago
import 'package:new_recook/utils/alert.dart';
2 years ago
import 'package:permission_handler/permission_handler.dart';
import 'headers.dart';
class PermissionTool {
2 years ago
static Future<bool> haveLocationPermission() async {
bool permission = await Permission.location.isGranted;
if (!permission) {
await Permission.location.request();
permission = await Permission.location.isGranted;
}
return permission;
}
2 years ago
static Future<bool> haveCameraPermission() async {
bool permission = await Permission.camera.isGranted;
if (!permission) {
await Permission.camera.request();
permission = await Permission.camera.isGranted;
}
return permission;
}
static Future<bool> haveStoragePermission() async {
bool permission = await Permission.storage.isGranted;
if (!permission) {
await Permission.storage.request();
permission = await Permission.storage.isGranted;
}
return permission;
}
static Future<bool> haveNotificationPermission() async {
bool permission = await Permission.notification.isGranted;
if (!permission) {
await Permission.notification.request();
permission = await Permission.notification.isGranted;
}
return permission;
}
static Future<bool> havePhotoPermission() async {
bool permission = await Permission.storage.isGranted;
if (!permission) {
await Permission.storage.request();
permission = await Permission.storage.isGranted;
}
return permission;
}
static Future<bool> haveAudioPermission() async {
bool permission = await Permission.microphone.isGranted;
if (!permission) {
await Permission.microphone.request();
permission = await Permission.microphone.isGranted;
}
return permission;
}
static Future<bool> haveContactPermission() async {
bool permission = await Permission.contacts.isGranted;
if (!permission) {
await Permission.contacts.request();
permission = await Permission.contacts.isGranted;
}
return permission;
}
static showOpenPermissionDialog(BuildContext context, String message,
2 years ago
{Function? open, String? title}) {
Alert.show(
context,
NormalTextDialog(
title: title != null ? title : '权限申请',
type: NormalTextDialogType.delete,
content: message,
items: ["取消"],
listener: (index) {
Alert.dismiss(context);
//Toast.showInfo('如果您后续需要接收消息通知,可在设置里打开');
},
deleteItem: "去开启",
deleteListener: () async {
Alert.dismiss(context);
await openAppSettings();
},
));
2 years ago
}
2 years ago
}