Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web hasPermission() throwing TypeError for standard use #987

Open
aardrop opened this issue Aug 22, 2024 · 3 comments
Open

Web hasPermission() throwing TypeError for standard use #987

aardrop opened this issue Aug 22, 2024 · 3 comments

Comments

@aardrop
Copy link

aardrop commented Aug 22, 2024

Describe the bug
This method per the documentation seems to work perfectly on iOS and Android but on Web I'm getting a random type error within the package.

Here's my code:

_serviceEnabled = await location.serviceEnabled();
  if (!_serviceEnabled) {
    _serviceEnabled = await location.requestService();
    if (!_serviceEnabled) {
      StackTrace.current
          .printWithInfo('No User Location Available: Services Not Enabled!');
      streamController.add(_initialFocusLocation);
      return;
    }
  }

  _permissionGranted = await location.hasPermission();
  if (_permissionGranted == PermissionStatus.denied ||
      _permissionGranted == PermissionStatus.deniedForever) {
    _permissionGranted = await location.requestPermission();
    if (_permissionGranted != PermissionStatus.granted ||
        _permissionGranted != PermissionStatus.grantedLimited) {
      StackTrace.current
          .printWithInfo('No User Location Available: Permission Not Granted!');
      streamController.add(_initialFocusLocation);
      return;
    }
  }

The error is thrown at location.hasPermission() and serviceEnabled returns true.

TypeError: Failed to execute 'query' on 'Permissions': Failed to read the 'name' property from 'PermissionDescriptor': Required member is undefined.
packages/location_web/location_web.dart 60:15                               hasPermission

Does anyone have this working on the web?

Tested on:
Packages and versions:
location: 6.0.2
flutter: 3.22.2
dart: 3.4.3

Expected Behavior:
On iOS and Android, this code works fine regardless of permission level. I would expect it to return some enum value instead of throwing a TypeError. Even if the location is not supported on the web at all, I would expect some level of a named error with instructions on some resolution or advising not to use this package and method for this platform.

@JEThilenius
Copy link

Interested as well if anyone has this working on web.

@tientt1304
Copy link

I faced the same error with the web. Has anyone fixed it?

@Nimo11
Copy link

Nimo11 commented Sep 17, 2024

After some investigation it seems that the problem comes from the permission_handler_html plugin used in flutter Web.
(documented here)

a permission_handler_html update fixes the problem version 0.1.3+1

Since a new update removes "PermissionDescripttor" from flutter Web and permission_handler_html (change log).

The temporary solution at this stage is to use the following overrides;

dependencies overrides: web: 0.5.1 permission_handler_html: 0.1.3+1

In pubspec.yaml waiting for a plugin update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants