requestPermissions method
Asks for everything the flow needs and reports where that leaves it.
Every permission that is not granted is requested, including one that already reads as permanently denied. The OS prompts only for what it still can and answers at once for the rest, so requesting costs nothing, while trusting the status can: on Android "permanently denied" is permission_handler's guess, made from a flag it stores and never clears, and a stale guess would skip a prompt the OS would still have shown.
Implementation
Future<PermissionOutcome> requestPermissions() async {
final answers = await _request(requiredPermissions);
// Only the permissions asked for. Android's plugin also reports sibling
// groups it touched along the way (location, speech, and on Android 9
// background location), which are not the flow's to judge and would
// otherwise reach the dialog under their raw names.
final statuses = {
for (final permission in requiredPermissions)
permission: answers[permission] ?? PermissionStatus.denied,
};
final location = statuses[locationPermission]!;
var approximateLocationOnly = false;
var locationServiceEnabled = true;
if (location.isGranted || location.isPermanentlyDenied) {
// The current status can tell two things the answer cannot:
// - Android answers granted for approximate location, but the status
// stays blocked until precise location is allowed as well.
// - An iOS build that left location out of its Podfile answers
// permanently denied, yet reads plain denied. A real denial reads
// permanently denied both ways — and so does Location Services
// being off device-wide, which iOS reports as a denial. The device
// setting is therefore checked only where it could be to blame,
// never for a build that cannot ask for location at all.
final current = await locationPermission.status;
approximateLocationOnly = location.isGranted && !current.isGranted;
if (approximateLocationOnly) statuses[locationPermission] = current;
if (location.isGranted || current.isPermanentlyDenied) {
locationServiceEnabled = await isLocationServiceEnabled();
}
}
return PermissionOutcome(
statuses,
approximateLocationOnly: approximateLocationOnly,
locationServiceEnabled: locationServiceEnabled,
);
}