Flutter: Requesting Runtime Permissions
Don't assume your app has access to the camera or contacts; you must ask the user for permission at runtime. This is required for features like photo uploads or location tracking. The common footgun is forgetting to declare permissions in native config files.
WHY IT EXISTS Modern operating systems prioritize user privacy and control. Granting all permissions at install time was a security risk, as users rarely reviewed them. Runtime permissions force apps to justify their need for sensitive data in context, giving users granular control and building trust.
THE MENTAL MODEL Requesting a permission is a two-step process. First, you declare your app's intent to use a permission to the OS in your native configuration files (like listing ingredients for a recipe). Second, you make the actual request to the user at the appropriate moment in your app's code (like asking to borrow an ingredient). Both steps are mandatory for the request to work.
HOW IT WORKS A plugin like permission_handler provides a unified Dart API for native permission dialogs. The typical flow is to first check a permission's status. If it's not granted, you call a request method. The OS then presents a standard dialog to the user. Your code receives the user's choice—grant, deny, or permanently deny—and must handle each case gracefully. For example, if denied, you might disable the feature or show a message explaining why it's needed.
WHEN TO USE IT Request a permission at the exact moment it's needed, not on app startup. For example, ask for camera permission only when the user taps a button to take a picture. This contextual request makes the need obvious to the user and increases the chance of approval. It feels helpful, not intrusive.
WHEN NOT TO USE IT Do not bombard the user with multiple permission requests when the app first launches. This is a poor user experience, leads to denials, and makes your app seem untrustworthy. Only ask for what you need, when you need it. You also don't need to request permissions for resources your app owns, like its own sandboxed storage directory.
ONE CANONICAL EXAMPLE To use the device camera, you must first add a usage description to your iOS Info.plist file (e.g., NSCameraUsageDescription) and a uses-permission tag to your Android AndroidManifest.xml file (e.g., android.permission.CAMERA). Only then, in your Dart code, can you call await Permission.camera.request(); right before initializing the camera. If the user denies the request, your app should handle this state by showing a message that the feature is unavailable without the permission.
Read the original → pub.dev
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.