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.
Interview question
According to the mental model for Flutter runtime permissions, what is a mandatory prerequisite before your Dart code can successfully request a sensitive permission from the user?
- a.Implementing a fallback mechanism for when the permission is denied.
- b.Displaying a custom dialog to the user explaining the permission's purpose.
- c.Declaring the app's intent to use the permission in native configuration files.Correct
- d.Checking the current permission status using a plugin like permission_handler.
Why? this is the answer
The card explicitly states that declaring the permission in native configuration files is the "first" step and that "Both steps are mandatory for the request to work." Without this native declaration, the operating system will not recognize or process the runtime permission request. While other options are good practices, they are not mandatory prerequisites for the request itself to function.
Just read this? Test yourself on what you have been reading.
Read the original → pub.dev
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.
See open roles