mapbox / mapbox-maps-flutter

Interactive, thoroughly customizable maps for Flutter powered by Mapbox Maps SDK
https://www.mapbox.com/mobile-maps-sdk
Other
284 stars 117 forks source link

TransparentPointer fail #116

Open sqcsabbey opened 1 year ago

sqcsabbey commented 1 year ago

I'm trying to switch from using the flutter-mapbox-gl plugin to this one, and I ran into an issue...

I'm using a transparent pointer over the map, in a Stack widget, so I can turn off some automated panning and zooming if the user starts interacting with the map; I'm interpreting gestures as pans, zooms, and rotates, and also letting the gestures bubble through to the map. This works fine with that other mapbox plugin, but with this one I get:

I/flutter ( 8823): ⚠️ Unhandled Flutter error: 'package:flutter/src/gestures/tap.dart': Failed assertion: line 210 pos 14: '_down == null && _up == null': is not true.

======== Exception caught by gesture library =======================================================
The following assertion was thrown while dispatching a pointer event:
'package:flutter/src/gestures/tap.dart': Failed assertion: line 210 pos 14: '_down == null && _up == null': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack: 
#2      BaseTapGestureRecognizer.addAllowedPointer (package:flutter/src/gestures/tap.dart:210:14)
#3      GestureRecognizer.addPointer (package:flutter/src/gestures/recognizer.dart:160:7)
#4      RawGestureDetectorState._handlePointerDown (package:flutter/src/widgets/gesture_detector.dart:1498:18)
#5      RenderPointerListener.handleEvent (package:flutter/src/rendering/proxy_box.dart:3168:29)
#6      GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:440:22)
#7      RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:336:11)
#8      GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:395:7)
#9      GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:357:5)
#10     GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:314:7)
#11     GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:295:7)
#12     _invoke1 (dart:ui/hooks.dart:164:13)
#13     PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:361:7)
#14     _dispatchPointerDataPacket (dart:ui/hooks.dart:91:31)
(elided 2 frames from class _AssertionError)
Event: PointerDownEvent#85236(position: Offset(222.0, 753.2))
  position: Offset(222.0, 753.2)
Target: RenderPointerListener#00676 relayoutBoundary=up8
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=411.4, 0.0<=h<=819.4)
  size: Size(411.4, 819.4)
  behavior: deferToChild
  listeners: down, panZoomStart

Is there a way to make this work?

Alternatively, is there a way to listen for user initiated zooms, pans, and rotates with this package?

scelza commented 1 year ago

I'm working with @sqcsabbey on this project, and would also mention that this implementation is working for our current flutter-mapbox-gl map plugin.

I'm curious if you're doing any custom gesture handling that isn't directly compatible with the user gesture that's passed through the transparent pointer?

As @sqcsabbey mentioned, if there's a way to listen for user initiated gestures, we may be able to avoid using the transparent pointer interception altogether.

If it's helpful to understand our use case, we have a feature that is similar to "follow user location" feature, the one that keeps the user location centered on the map. In our feature, we keep the user location and a selected point visible together as a pair. This calculates the bounds that contain the two points, and zooms the map as close as it can while keeping both points visible. When a user manually pans or zooms, we toggle this feature off, and therefore need to capture the gesture to make this determination.

scelza commented 1 year ago

Bumping this to see if there are any recommended gesture handling best practices with this plugin for our situation?

I've submitted a Discord post on this as well: https://discord.com/channels/1004826913229000704/1093609540362178692