您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了如何使用Flutter permission_handler權(quán)限插件,內(nèi)容簡而易懂,希望大家可以學(xué)習(xí)一下,學(xué)習(xí)完之后肯定會有收獲的,下面讓小編帶大家一起來看看吧。
編譯環(huán)境:Flutter 版本v1.12.hotfix9 dart SDK:2.7.2
1 pubspec.yaml中引入:
# 權(quán)限
permission_handler: ^3.2.0
ios中info.plist配置(根據(jù)權(quán)限情況使用):
<!-- Permission options for the `location` group --> <key>NSLocationWhenInUseUsageDescription</key> <string>Need location when in use</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>Always and when in use!</string> <key>NSLocationUsageDescription</key> <string>Older devices need location.</string> <key>NSLocationAlwaysUsageDescription</key> <string>Can I haz location always?</string> <!-- Permission options for the `mediaLibrary` group --> <key>NSAppleMusicUsageDescription</key> <string>Music!</string> <key>kTCCServiceMediaLibrary</key> <string>media</string> <!-- Permission options for the `calendar` group --> <key>NSCalendarsUsageDescription</key> <string>Calendars</string> <!-- Permission options for the `camera` group --> <key>NSCameraUsageDescription</key> <string>camera</string> <!-- Permission options for the `contacts` group --> <key>NSContactsUsageDescription</key> <string>contacts</string> <!-- Permission options for the `microphone` group --> <key>NSMicrophoneUsageDescription</key> <string>microphone</string> <!-- Permission options for the `speech` group --> <key>NSSpeechRecognitionUsageDescription</key> <string>speech</string> <!-- Permission options for the `sensors` group --> <key>NSMotionUsageDescription</key> <string>motion</string> <!-- Permission options for the `photos` group --> <key>NSPhotoLibraryUsageDescription</key> <string>photos</string> <!-- Permission options for the `reminder` group --> <key>NSRemindersUsageDescription</key> <string>reminders</string>
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 總結(jié):
在使用的過程中可能會出現(xiàn)androidX 或者Swift語言的適配,這時候需要根據(jù)具體情況進(jìn)行修改。
以上就是關(guān)于如何使用Flutter permission_handler權(quán)限插件的內(nèi)容,如果你們有學(xué)習(xí)到知識或者技能,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。