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 · 4 comments
Open

Web hasPermission() throwing TypeError for standard use #987

aardrop opened this issue Aug 22, 2024 · 4 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.

@JEThilenius
Copy link

JEThilenius commented Oct 3, 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.

Thanks for the investigation. Unfortunately the temporary solution doesn't seem to work when there are other packages that also rely on web. I set the overrides as you specified
dependency_overrides: web: 0.5.1 permission_handler_html: 0.1.3+1

Im using the following package versions:
location: ^7.0.0
Flutter version 3.24.3
Dart version 3.5.3

And get the following error:

`Launching lib/main.dart on Chrome in debug mode...
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:19:12: Error: Type 'web.TrustedTypePolicyFactory' not found.
external web.TrustedTypePolicyFactory? get nullableTrustedTypes;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:24:41: Error: Type 'web.TrustedTypePolicy' not found.
extension CreateScriptUrlWithoutArgs on web.TrustedTypePolicy {
^^^^^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:27:12: Error: Type 'web.TrustedScriptURL' not found.
external web.TrustedScriptURL createScriptURLNoArgs(
^^^^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:36:30: Error: Type 'web.TrustedScript' not found.
external set trustedScript(web.TrustedScript value);
^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/firebase_core_web.dart:122:19: Error: 'TrustedTypePolicy' isn't a type.
final web.TrustedTypePolicy policy =
^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/firebase_core_web.dart:125:15: Error: Method not found: 'TrustedTypePolicyOptions'.
web.TrustedTypePolicyOptions(
^^^^^^^^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/firebase_core_web.dart:123:24: Error: The getter 'trustedTypes' isn't defined for the class 'Window'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'trustedTypes'.
web.window.trustedTypes.createPolicy(
^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/printing-5.13.3/lib/printing_web.dart:217:16: Error: A value of type 'JSString' can't be assigned to a variable of type 'String'.
.toJS;
^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:36:34: Error: 'TrustedScript' isn't a type.
external set trustedScript(web.TrustedScript value);
^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/geolocator_web-4.1.1/lib/src/utils.dart:12:22: Error: The argument type 'num' can't be assigned to the parameter type 'double'.
latitude: coords.latitude,
^
../../.pub-cache/hosted/pub.dev/geolocator_web-4.1.1/lib/src/utils.dart:13:23: Error: The argument type 'num' can't be assigned to the parameter type 'double'.
longitude: coords.longitude,
^
../../.pub-cache/hosted/pub.dev/geolocator_web-4.1.1/lib/src/utils.dart:15:31: Error: The argument type 'num' can't be assigned to the parameter type 'double'.
altitude: coords.altitude ?? 0.0,
^
../../.pub-cache/hosted/pub.dev/geolocator_web-4.1.1/lib/src/utils.dart:16:47: Error: The argument type 'num' can't be assigned to the parameter type 'double'.
altitudeAccuracy: coords.altitudeAccuracy ?? 0.0,
^
../../.pub-cache/hosted/pub.dev/geolocator_web-4.1.1/lib/src/utils.dart:18:29: Error: The argument type 'num' can't be assigned to the parameter type 'double'.
heading: coords.heading ?? 0.0,
^
../../.pub-cache/hosted/pub.dev/geolocator_web-4.1.1/lib/src/utils.dart:21:25: Error: The argument type 'num' can't be assigned to the parameter type 'double'.
speed: coords.speed ?? 0.0,
^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:19:46: Error: External JS interop member contains an invalid type: 'invalid-type'.
Use one of these valid types instead: JS types from 'dart:js_interop', ExternalDartReference, void, bool, num, double, int, String, extension types that erase to one of these types, '@staticInterop' types, 'dart:html' types when compiling to JS, or a type parameter that is a subtype of a valid non-primitive type.
external web.TrustedTypePolicyFactory? get nullableTrustedTypes;
^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:27:33: Error: JS interop type or @Native type from an SDK web library required for 'external' extension members.
Try making the on-type a JS interop type or an @Native SDK web library type.
external web.TrustedScriptURL createScriptURLNoArgs(
^
../../.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart:36:16: Error: External JS interop member contains an invalid type: 'invalid-type'.
Use one of these valid types instead: JS types from 'dart:js_interop', ExternalDartReference, void, bool, num, double, int, String, extension types that erase to one of these types, '@staticInterop' types, 'dart:html' types when compiling to JS, or a type parameter that is a subtype of a valid non-primitive type.
external set trustedScript(web.TrustedScript value);
^
Unhandled exception:
Unsupported operation: Unsupported invalid type InvalidType() (InvalidType). Encountered while compiling file:///Users/jet/.pub-cache/hosted/pub.dev/firebase_core_web-2.18.1/lib/src/interop/package_web_tweaks.dart, which contains the type: FunctionType( Function(String)).
#0 ProgramCompiler._typeCompilationError (package:dev_compiler/src/kernel/compiler.dart:3224)
#1 ProgramCompiler._emitType (package:dev_compiler/src/kernel/compiler.dart:3185)
#2 ProgramCompiler._emitFunctionTagged (package:dev_compiler/src/kernel/compiler.dart:3031)
#3 ProgramCompiler.visitFunctionExpression (package:dev_compiler/src/kernel/compiler.dart:7027)
#4 FunctionExpression.accept (package:kernel/ast.dart:8588)
#5 ProgramCompiler._visitExpression (package:dev_compiler/src/kernel/compiler.dart:3925)
#6 ProgramCompiler.visitReturnStatement (package:dev_compiler/src/kernel/compiler.dart:4615)
#7 ReturnStatement.accept (package:kernel/ast.dart:10140)
#8 ProgramCompiler._visitStatement (package:dev_compiler/src/kernel/compiler.dart:3834)
#9 ProgramCompiler._emitFunctionScopedBody (package:dev_compiler/src/kernel/compiler.dart:3867)
#10 ProgramCompiler._emitSyncFunctionBody. (package:dev_compiler/src/kernel/compiler.dart:3573)
#11 ProgramCompiler._withLetScope (package:dev_compiler/src/kernel/compiler.dart:2553)
#12 ProgramCompiler._withCurrentFunction (package:dev_compiler/src/kernel/compiler.dart:3610)
#13 ProgramCompiler._emitSyncFunctionBody (package:dev_compiler/src/kernel/compiler.dart:3569)
#14 ProgramCompiler._emitFunction (package:dev_compiler/src/kernel/compiler.dart:3385)
#15 ProgramCompiler._emitLibraryFunction (package:dev_compiler/src/kernel/compiler.dart:2986)
#16 MappedIterator.moveNext (dart:_internal/iterable.dart:403)
#17 new _GrowableList._ofOther (dart:core-patch/growable_array.dart:202)
#18 new _GrowableList.of (dart:core-patch/growable_array.dart:152)
#19 new List.of (dart:core-patch/array_patch.dart:39)
#20 Iterable.toList (dart:core/iterable.dart:498)
#21 ProgramCompiler._emitLibraryProcedures (package:dev_compiler/src/kernel/compiler.dart:2912)
#22 ProgramCompiler._emitLibrary (package:dev_compiler/src/kernel/compiler.dart:758)
#23 List.forEach (dart:core-patch/growable_array.dart:417)
#24 ProgramCompiler.emitModule (package:dev_compiler/src/kernel/compiler.dart:486)
#25 IncrementalJavaScriptBundler.compile (package:frontend_server/src/javascript_bundle.dart:221)
#26 FrontendCompiler.writeJavaScriptBundle (package:frontend_server/frontend_server.dart:870)

#27 FrontendCompiler.compile (package:frontend_server/frontend_server.dart:685)

#28 listenAndCompile. (package:frontend_server/frontend_server.dart:1385)

the Dart compiler exited unexpectedly.
Failed to compile application.

Exited (1).
`

I'd prefer not to have to revert all the above packages to versions that are compatible with web: 0.5.1... Any other ideas/solutions? Or am I misinterpreting the error? Thanks!

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