flutter_animarker icon indicating copy to clipboard operation
flutter_animarker copied to clipboard

Unhandled Exception: Unknown marker ID "99" in InfoWindow onTap in Animarker

Open anish769 opened this issue 2 years ago • 5 comments

image image

anish769 avatar Aug 10 '22 11:08 anish769

This is my animarker code image

anish769 avatar Aug 10 '22 11:08 anish769

It works when I set marker in Google Map but I need marker in animarker widget

anish769 avatar Aug 10 '22 11:08 anish769

Hello did you figure this out?

skitsa1 avatar Jan 19 '23 21:01 skitsa1

Hello, same problem An issue on this topic has already been opened and closed without being answered or corrected.

The only (very bad) "solution" is to duplicate the markers set and assign it to GoogleMap's "marker:" but this causes a duplication of the markers on the map, those animated by Animarker and the static ones from GoogleMap, so they're all duplicated. Even by forcing the visibility of GoogleMap markers to false and setting an invisible icon, GoogleMap markers are still present and unchanged.

A solution is urgently needed, because as soon as you define a marker in Animarker and tap on it, the application crashes with the error "UnknownMapObjectIdError (Unknown marker ID "00001" in onTap)".

Thanks.

Ludwig151 avatar Jan 11 '24 21:01 Ludwig151

I managed to work around the problem by patching a file in the google_maps_flutter package. The idea is to secure the onMarkerTap method while avoiding sending the exception. I thought I'd also have to modify the onInfoWindowTap method, but after testing, I've found that this isn't necessary. Tested on versions 3.2.0 and 3.4.0-beta.1 The file to be modified is : AppData\Local\Pub\Cache\hosted\pub.dev\google_maps_flutter-2.5.2\lib\src\google_map.dart So here's original and patched code:

// ----- PATCH TO AVOID INDEX EXCEPTION WHEN USE WITH FLUTTER_ANIMARKER -----
// ----- ORIGINAL VERSION :
// void onMarkerTap(MarkerId markerId) {
// final Marker? marker = _markers[markerId];
// if (marker == null) {
// throw UnknownMapObjectIdError('marker', markerId, 'onTap');
// }
// final VoidCallback? onTap = marker.onTap;
// if (onTap != null) {
// onTap();
// }
// }


// ----- PATCH TO AVOID INDEX EXCEPTION WHEN USE WITH FLUTTER_ANIMARKER -----
// ----- PATCHED VERSION :
void onMarkerTap(MarkerId markerId) {
  final Marker? marker = _markers[markerId];
  if (marker != null) {
    final VoidCallback? onTap = marker.onTap;
    if (onTap != null) {
      onTap();
    }
  }
}

Ludwig151 avatar Jan 12 '24 12:01 Ludwig151