flutter_map_location_marker icon indicating copy to clipboard operation
flutter_map_location_marker copied to clipboard

Web: MissingPluginException(No implementation found for method listen on channel native_device_orientation_events)

Open jithware opened this issue 5 months ago • 4 comments

Describe the bug When running the example app on web the following errors are produced:

The following MissingPluginException was thrown while activating platform stream on channel
native_device_orientation_events:
MissingPluginException(No implementation found for method listen on channel
native_device_orientation_events)
...
Another exception was thrown: MissingPluginException(No implementation found for method listen on channel
rotation_sensor/orientation)
DartError: Unsupported operation: add
...
DartError: MissingPluginException(No implementation found for method getOrientationStream on channel rotation_sensor/method)

To Reproduce Steps to reproduce the behavior:

  1. Execute: cd example && flutter run -d chrome
  2. Click on 'Minimum Example'
  3. Click on 'Allow while visiting site'
  4. See error in console

Expected behavior No error

Desktop:

  • Browser: Chrome Version 139.0.7258.66 (Official Build) (64-bit)

Additional context This may be a similar issue as reported in #35

jithware avatar Aug 13 '25 21:08 jithware

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Sep 13 '25 10:09 github-actions[bot]

Issue still present on Chrome Version 140.0.7339.80 (Official Build) (64-bit)

The following MissingPluginException was thrown while activating platform stream on channel
native_device_orientation_events:
MissingPluginException(No implementation found for method listen on channel
native_device_orientation_events)
...

jithware avatar Sep 13 '25 11:09 jithware

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Oct 14 '25 10:10 github-actions[bot]

un-stale

tlserver avatar Oct 15 '25 01:10 tlserver

I took a look at the commits for the proposed fix, and that's not a fix. The error should be handled, or prevented. Previously, you had the showHeadingSector: !kIsWeb route that could address this. But throwing an error is not supporting web.

jlambright avatar Nov 11 '25 18:11 jlambright

Thanks for the feedback, @jlambright—it's super helpful to get eyes on this, and I appreciate you taking the time to review the commit.

You're spot on that the showHeadingSector: !kIsWeb approach (floated back in #27 as a simple fix for the original MissingPluginException on web) was a clean preventive measure, and I agree prevention is ideal where possible. The goal here was to keep the API flexible (no hard defaults that might surprise users opting into the feature) while avoiding those raw plugin crashes. To that end:

  • We now check RotationSensor.isPlatformSupported upfront in data_stream_factory.dart, which skips the plugin invocation entirely on unsupported platforms like web (no MethodChannel calls, no unhandled exceptions).
  • If unsupported, we return a controlled Stream.error(UnsupportedException()) as a clear signal—typed and descriptive, so devs can catch it for custom fallbacks if needed (e.g., a static heading or web polyfill via dart:html).
  • Crucially, in CurrentLocationLayer, the widget's stream listener already handles this specific exception: it catches UnsupportedException, logs it only in debug mode, and immediately hides the heading sector (via state update, similar to setState(() => _showHeadingSector = false)). No further errors propagate, and the marker renders as a basic location dot without the overlay.

In practice, this makes the out-of-the-box experience on web nearly identical to the #27 suggestion: the feature degrades silently to "off" on init, with zero console noise in release builds. The one-time error emission is contained and doesn't affect perf or UX.

Looking forward to your thoughts!

tlserver avatar Nov 13 '25 13:11 tlserver