[Bug]: Permission.locationAlways.request doesn't wait for selection in system dialog
Please check the following before submitting a new issue.
- [x] I have searched the existing issues.
- [x] I have carefully read the documentation and verified I have added the required platform specific configuration.
Please select affected platform(s)
- [ ] Android
- [x] iOS
- [ ] Windows
Steps to reproduce
When calling await Permission.locationAlways.request() system dialog is shown but lib is not waiting for a selection, instead it just returns .denied.
Expected results
To wait for a selection in location permission system dialog.
Actual results
PermissionStatus.denied is returned right away.
Code sample
Code sample
import 'dart:async';
import 'package:permission_handler/permission_handler.dart';
import 'package:vegetation_manager/common/helper/location_permission_manager.dart';
final class LocationPermissionManagerImpl implements LocationPermissionManager {
@override
Future<bool> isLocationAlwaysAllowed() async {
var locationAlwaysStatus = await Permission.locationAlways.status;
if (!locationAlwaysStatus.isGranted) {
final whenInUseStatus = await Permission.locationWhenInUse.request();
if (whenInUseStatus.isGranted) {
// Not waiting for user to choose option in dialog, instead returning .denied right away
locationAlwaysStatus = await Permission.locationAlways.request();
return locationAlwaysStatus.isGranted;
}
return false;
}
return true;
}
}
Screenshots or video
Screenshots or video demonstration
[Upload media here]
Version
11.4.0
Flutter Doctor output
Doctor output
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.27.0, on macOS 15.3.1 24D70 darwin-arm64, locale en-RS)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.98.0)
[✓] Connected device (5 available)
[✓] Network resources
• No issues found!
I run into the same error -- same parameters.
I got the same error
Did someone find any solutions?
I have made a timer to check for Permission.locationAlways.status every second until it is granted. It's not pretty but it works with some edge cases.
I have made a timer to check for Permission.locationAlways.status every second until it is granted. It's not pretty but it works with some edge cases.
What if user deny the permission?
I have made a timer to check for Permission.locationAlways.status every second until it is granted. It's not pretty but it works with some edge cases.
What if user deny the permission?
I'm waiting for 30 seconds, if it's not granted in that period I assume it's denied.
@v1n4ester This is not optimal, as you also said. The location and locationWhenInSure both work, so the locationAlways should work by extension. It's therefore a bug that should be addressed via either a PR or by the community maintaining the plugin.
any updates? I would imagine this is high priority for many devs
any updates? I would imagine this is high priority for many devs
Nope, problem still exist
I got the same error
Same.
similar with my issue on latest version. stuck at calling Permission.locationAlways.request(), not opening permission dialog instead. I got this warning and exception:
W/Activity(17584): Can request only one set of permissions at a time
PlatformException(PermissionHandler.PermissionManager, A request for permissions is already running, please wait for it to finish before doing another request (note that you can request multiple permissions at the same time)., null, null)
but no permission dialog is opening before.
Got similar issue while requesting both location and Phone
W/Activity( 7365): Can request only one set of permissions at a time
W/permissions_handler( 7365): onRequestPermissionsResult is called without results. This is probably caused by interfering request codes. If you see this error, please file an issue in flutter-permission-handler, including a list of plugins used by this application: https://github.com/Baseflow/flutter-permission-handler/issues
final status = await [ Permission.location, Permission.phone].request();
permission_handler: 11.3.1 , Flutter: 3.24.3
I emulated expected behavior for my case by this way. Hope it will help somebody
bool _whileInUseGranted = false;
bool _alwaysGranted = false;
bool _notificationGranted = false;
Timer? _alwaysPermissionCheckTimer;
bool checkingAlways = false;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
_checkPermissions();
}
@override
void dispose() {
_alwaysPermissionCheckTimer?.cancel();
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print("state: " + state.toString());
if (state == AppLifecycleState.resumed) {
_checkPermissions();
}
}
Future<void> _checkPermissions() async {
setState(() => _loading = true);
final locStatus = await Permission.location.status;
final alwaysStatus = await Permission.locationAlways.status;
final notifStatus = await Permission.notification.status;
setState(() {
_whileInUseGranted = locStatus.isGranted;
_alwaysGranted = alwaysStatus.isGranted;
_notificationGranted = notifStatus.isGranted;
_loading = false;
});
if (checkingAlways && alwaysStatus.isPermanentlyDenied) {
checkingAlways = false;
_alwaysPermissionCheckTimer?.cancel();
_showLocationSettingsDialog();
}
if (_alwaysGranted && _notificationGranted) {
_continueToApp();
}
}
Future<void> _requestAlwaysPermission() async {
final res = await Permission.locationAlways.request();
if (res.isGranted) {
setState(() => _alwaysGranted = true);
if (_notificationGranted) _continueToApp();
return;
}
if (res.isDenied) {
checkingAlways = true;
_alwaysPermissionCheckTimer = Timer.periodic(Duration(seconds: 1), (
timer,
) async {
final updatedStatus = await Permission.locationAlways.status;
if (updatedStatus.isGranted) {
timer.cancel();
checkingAlways = false;
setState(() => _alwaysGranted = true);
if (_notificationGranted) _continueToApp();
}
});
return;
}
if (res.isPermanentlyDenied) {
_showLocationSettingsDialog();
}
}
In IOS permission pop up is not work in real device i try many times but not working.
I got the same error