gpt4 book ai didi

flutter - 尝试为相机,麦克风和抖动上的 map 写入权限

转载 作者:行者123 更新时间:2023-12-03 03:08:41 25 4
gpt4 key购买 nike

尝试为相机,麦克风和 flutter 器上的 map 编写权限代码

这是代码,请这段代码有什么问题

将其保存在可访问的dart文件中


class Permissions {
static Future<bool> cameraAndMicrophonePermissionsGranted() async {
PermissionStatus cameraPermissionStatus = await _getCameraPermission();
PermissionStatus microphonePermissionStatus =
await _getMicrophonePermission();

if (cameraPermissionStatus == PermissionStatus.granted &&
microphonePermissionStatus == PermissionStatus.granted) {
return true;
} else {
_handleInvalidPermissions(
cameraPermissionStatus, microphonePermissionStatus);
return false;
}
}

static Future<PermissionStatus> _getCameraPermission() async {
PermissionStatus permission =
await PermissionHandler().checkPermissionStatus(PermissionGroup.camera);
if (permission != PermissionStatus.granted &&
permission != PermissionStatus.disabled) {
Map<PermissionGroup, PermissionStatus> permissionStatus =
await PermissionHandler()
.requestPermissions([PermissionGroup.camera]);
return permissionStatus[PermissionGroup.camera] ??
PermissionStatus.unknown;
} else {
return permission;
}
}

static Future<PermissionStatus> _getMicrophonePermission() async {
PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.microphone);
if (permission != PermissionStatus.granted &&
permission != PermissionStatus.disabled) {
Map<PermissionGroup, PermissionStatus> permissionStatus =
await PermissionHandler()
.requestPermissions([PermissionGroup.microphone]);
return permissionStatus[PermissionGroup.microphone] ??
PermissionStatus.unknown;
} else {
return permission;
}
}

static void _handleInvalidPermissions(
PermissionStatus cameraPermissionStatus,
PermissionStatus microphonePermissionStatus,
) {
if (cameraPermissionStatus == PermissionStatus.denied &&
microphonePermissionStatus == PermissionStatus.denied) {
throw new PlatformException(
code: "PERMISSION_DENIED",
message: "Access to camera and microphone denied",
details: null);
} else if (cameraPermissionStatus == PermissionStatus.disabled &&
microphonePermissionStatus == PermissionStatus.disabled) {
throw new PlatformException(
code: "PERMISSION_DISABLED",
message: "Location data is not available on device",
details: null);
}
}
}


错误是

没有在类“Permissions”中定义
  • 方法“PermissionHandler”
  • 未定义的名称“PermissionGroup”
  • 在类PermissionStatus
  • 中未定义获取方法“禁用”
  • 名称“PermissionGroup”不是类型,因此不能用作类型参数
  • 未定义名称“已禁用”

  • 此代码有什么问题?

    最佳答案

    您的代码使用permission_handler 3.3.0pubspec.yaml中,您必须指定3.3.0版本

    dependencies:
    flutter:
    sdk: flutter
    permission_handler: 3.3.0

    关于flutter - 尝试为相机,麦克风和抖动上的 map 写入权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61070511/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com