Sub topic 7
Explaining Why You Need Location
Assume you know basic Flutter widgets, Dart async and await, and how to request permissions with geolocator or permission_handler. This chapter focuses on the user experience around the request, not on the platform declarations or position APIs.
A permission dialog tells users what the operating system is protecting. It does not always explain why your app needs access at that moment. Your app should provide that explanation before requesting location.
Give the explanation at the right time
Ask for location when the user starts an action that needs it. For example, request access when the user taps Find nearby stores, not immediately when the app opens.
A good explanation answers three questions:
- What feature needs location?
- How will the app use the location?
- When will the app use it?
For example:
> We use your location to show stores near you while this screen is open. We do not need location for other parts of the app.
This message is specific and limited. Avoid vague claims such as “We need location to improve your experience.” Users cannot use that statement to make an informed choice.
| Weak explanation | Better explanation |
|---|---|
| “Location is required.” | “We use your location to sort these results by distance.” |
| “Allow access for full functionality.” | “Allow access to show nearby charging stations.” |
| “We collect your location.” | “We read your location while this search is open.” |
Show a rationale before the system dialog
A rationale is a short explanation shown by your app before the operating system asks for permission. It should not pretend to be the permission dialog, and it should not pressure the user.
The following function returns true only when the user chooses to continue:
import 'package:flutter/material.dart';
Future<bool> explainLocationNeed(BuildContext context) async {
final result = await showDialog<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('Find nearby places'),
content: const Text(
'We use your location to sort places by distance while '
'this search is open.',
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('Not now'),
),
FilledButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('Continue'),
),
],
);
},
);
return result ?? false;
}Call this function before the permission request. If it returns false, stop the flow without showing the platform dialog. The user has declined the explanation, so asking again immediately would feel coercive.
flowchart TD
A[User taps a location feature] --> B[Show a clear rationale]
B --> C{User chooses Continue?}
C -->|No| D[Stop without requesting]
C -->|Yes| E[Check and request platform permission]
E --> F[Continue only if access is granted]Respect each permission outcome
A user can deny access and still use parts of the app. Design a useful fallback, such as manual city selection or a map search without the device location.
If access is permanently denied, repeatedly showing your rationale will not fix the problem. Explain that the user can enable access in system settings, then provide a settings action when appropriate. Do not send the user to settings without telling them why.
On Android and iOS, the wording and available choices in the system dialog can differ. Your in-app explanation should therefore describe the feature and intended use, not promise an exact button label or permission state.
Exercise
Exercise
A weather screen requests location as soon as the app starts. What UX change would you make?
Show answer
Request location when the user opens the local forecast feature, and first explain that the location is used to select the forecast for the current area.