编译环境:Flutter 版本v1.12.hotfix9 dart SDK:2.7.2
1 pubspec.yaml中引入:
# 权限
permission_handler: ^3.2.0
ios中info.plist配置(根据权限情况使用):
NSLocationWhenInUseUsageDescription Need location when in use NSLocationAlwaysAndWhenInUseUsageDescription Always and when in use! NSLocationUsageDescription Older devices need location. NSLocationAlwaysUsageDescription Can I haz location always? NSAppleMusicUsageDescription Music! kTCCServiceMediaLibrary media NSCalendarsUsageDescription Calendars NSCameraUsageDescription camera NSContactsUsageDescription contacts NSMicrophoneUsageDescription microphone NSSpeechRecognitionUsageDescription speech NSMotionUsageDescription motion NSPhotoLibraryUsageDescription photos NSRemindersUsageDescription reminders
2 代码中具体使用:
void chosePhoto(int index) async {
PermissionHandler().requestPermissions(
[PermissionGroup.photos, PermissionGroup.camera]).then((map) {
if (map[PermissionGroup.photos] == PermissionStatus.granted ||
map[PermissionGroup.camera] == PermissionStatus.granted) {
chosePhotoFromPhone(context, index);
}
});
}
3 总结:
在使用的过程中可能会出现androidX 或者Swift语言的适配,这时候需要根据具体情况进行修改。
到此这篇关于Flutter permission_handler 权限插件的使用的文章就介绍到这了,更多相关Flutter permission_handler 权限插件内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!



