Sub topic 1
How Runtime Permissions Work on Android and iOS
Location is protected data. A Flutter app cannot read it simply because the device has GPS hardware. The operating system must allow the app to use location, and the user normally grants that access while the app is running.
This process has two parts:
- The app declares the location access it may need in platform configuration.
- The app requests access at runtime, and the user chooses whether to grant it.
The declaration tells the platform what the app might do. The runtime request asks for the user’s decision. Both parts are required.
Prerequisites
This chapter assumes that you know basic Dart and Flutter widgets, can use async and await with Futures, and can add packages with pub. You should also be comfortable opening the Android and iOS folders in a Flutter project.
The operating system is the permission owner
Flutter code runs inside an application controlled by Android or iOS. A package such as geolocator connects Flutter to each platform’s permission APIs, but it does not bypass them.
The operating system decides:
- Whether the request can be shown.
- Which choices appear in the permission dialog.
- Whether the app receives approximate or precise location.
- Whether the app can ask again.
- Whether the user must change the choice in system settings.
Your app should treat the platform’s result as authoritative. Do not assume that a request succeeded because the request completed without throwing an exception.
flowchart TD
A[Flutter app needs location] --> B[Platform declaration exists]
B --> C[Check current service and permission state]
C --> D{Permission already granted?}
D -- Yes --> E[Read location]
D -- No --> F[Ask the operating system]
F --> G{User decision}
G -- Grant --> E
G -- Deny --> H[Explain the limitation]
G -- Permanent denial --> I[Offer app settings]The declaration belongs in AndroidManifest.xml on Android and Info.plist on iOS. If the declaration is missing, the runtime request may fail, return an unusable result, or never show a dialog.
Android and iOS use different state models
The platforms expose similar ideas but do not use identical names. A Flutter package usually converts those native results into a common Dart API.
| Platform | Typical location choices | Important behavior |
|---|---|---|
| Android | Denied, approximate, precise, one-time, or allowed while using the app | The user can reduce accuracy or deny future requests |
| iOS | Not determined, denied, restricted, when in use, or always | The user chooses an authorization level and may need Settings later |
On Android, approximate location can satisfy an app that needs only a general area. Precise location is needed for tasks such as turn-by-turn navigation. Android can also grant temporary access for one use or for the current app session, depending on the system version and dialog choices.
On iOS, When In Use access allows location while the app is active. Always access is a stronger request for background behavior and has additional review and configuration requirements. An app should request the least access that meets its feature’s purpose.
Permission state is not the same as a service switch
A user can grant your app permission while location services are turned off in the device settings. The reverse can also happen: location services can be enabled while your app has no permission.
Check both conditions:
- Is the device location service enabled?
- Does this app have the required permission?
The first condition describes a device-wide setting. The second describes access for your application. A correct request flow handles them separately and gives the user a useful message for each case.
Permission decisions can change later
A permission result is not permanent application data. The user can change it in system settings, revoke it after granting it, or reduce its accuracy. Recheck the state when the feature starts and when the app returns to the foreground.
A denial should stop the location operation cleanly. A permanent denial usually means that another request will not show a dialog. In that case, the app can explain the limitation and offer a button that opens its settings page. The user remains in control.
Exercise
Exercise
Why must a Flutter app check both the location service state and the app permission state?
Show answer
The service state controls whether location is available on the device, while the permission state controls whether this app may use it. Either one can prevent a location request from succeeding.