Sub topic 3
Declaring Permissions in AndroidManifest.xml and Info.plist
This chapter assumes you know basic Dart and Flutter widgets, can edit pubspec.yaml, and understand async and await. It focuses on the platform files that must declare location access before Flutter can request it at runtime.
Why declarations are required
A Flutter package can call the Android or iOS permission APIs, but the operating system first checks the app's platform declaration.
The declaration answers this question:
> Which protected capability might this app use?
The user grant answers a different question:
> Does this user allow this app to use that capability now?
Both steps are required. If the declaration is missing, a runtime request can fail, return a denied status, or never show a useful permission dialog.
AndroidManifest.xml
Android declarations go in android/app/src/main/AndroidManifest.xml. Put the <uses-permission> elements directly under the root <manifest> element. They must not be placed inside <application>.
For location while the app is in use, declare coarse and fine location:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.location_demo">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:label="Location Demo"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<!-- Keep the activity and other generated Flutter entries here. -->
</application>
</manifest>ACCESS_COARSE_LOCATION allows approximate location. ACCESS_FINE_LOCATION allows more precise location when Android and the user permit it. Requesting fine location does not guarantee precise results. The user may choose approximate access instead.
For background location, Android uses an additional permission:
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />Add this only when the product genuinely needs location while the app is not visible. Background access has stricter platform behavior and store review requirements. Declaring it does not automatically grant it.
iOS Info.plist
iOS requires a usage description before it will show a location permission prompt. Add the key to ios/Runner/Info.plist inside the top-level <dict> element:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>Location Demo</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location to show nearby places while the app is open.</string>
</dict>
</plist>The description should explain the real feature in plain language. Do not use a vague message such as “Location is required.” The operating system displays this text in the permission prompt, so users need enough context to make an informed choice.
For background location, iOS may also require:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>We use your location to update your trip while the app runs in the background.</string>Use the background key only when the app has a valid background use case and the required background capabilities are configured.
Common declaration errors
| Error | Result |
|---|---|
| Putting Android permissions inside `<application>` | Android may ignore the declaration |
| Omitting the iOS usage description | iOS may refuse to show the prompt |
| Declaring background access unnecessarily | Extra review and user-trust concerns |
| Assuming declaration means permission is granted | Runtime checks are still required |
Exercise
Exercise
Where do you declare Android location permissions, and where do you put the iOS explanation shown to users?
Show answer
Put Android <uses-permission> elements directly under <manifest> in android/app/src/main/AndroidManifest.xml. Put iOS usage-description keys inside the top-level <dict> in ios/Runner/Info.plist.