OwnWeb / flutter_map_tappable_polyline

A tappable Polyline plugin for flutter_map
https://pub.dev/packages/flutter_map_tappable_polyline
MIT License
54 stars 44 forks source link

NullPointerException when hitting no polyline #20

Closed S-Man42 closed 3 years ago

S-Man42 commented 3 years ago

Hi,

I am getting this error when clicking on an empty space without any polyline:

======== Exception caught by gesture ===============================================================
The following NoSuchMethodError was thrown while handling a gesture:
The method 'call' was called on null.
Receiver: null
Tried calling: call()

When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1      TappablePolylineLayer._handlePolylineTap (package:flutter_map_tappable_polyline/flutter_map_tappable_polyline.dart:219:13)
#2      TappablePolylineLayer._build.<anonymous closure>.<anonymous closure> (package:flutter_map_tappable_polyline/flutter_map_tappable_polyline.dart:136:17)
#3      TapGestureRecognizer.handleTapUp.<anonymous closure> (package:flutter/src/gestures/tap.dart:596:57)
#4      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
...
Handler: "onTapUp"
Recognizer: TapGestureRecognizer#1bf24
  debugOwner: GestureDetector
  state: ready
  won arena
  finalPosition: Offset(66.5, 492.0)
  finalLocalPosition: Offset(66.5, 412.0)
  button: 1
  sent tap down
====================================================================================================

My code:

   layers.addAll([
      TappablePolylineLayerOptions(
        polylineCulling: true,
        polylines: _polylines,
        onTap: (polyline) => print(polyline.tag)
      ),
      MarkerLayerOptions(
        markers: _markers
      ),
      PopupMarkerLayerOptions(
        markers: _markers,
        popupSnap: PopupSnap.top,
        popupController: _popupLayerController,
        popupBuilder: (BuildContext _, Marker marker) => _buildPopups(marker)
      ),
    ]);

package:flutter_map_tappable_polyline/flutter_map_tappable_polyline.dart:219:13 points the else branch of following code is trying to call onMiss() if I am right:

if (hit) {
   ...
} else {
  onMiss();
}

Am I doing something wrong or is there a bug?

Kind regards, Mark

tuarrep commented 3 years ago

Thanks for reporting this.

It's on us. onMiss should be defaulted to an empty function.

We will be grateful to you to open a PR. If you wouldn't, you can pass an empty onMiss callback to TappablePolylineLayerOptions as a workaround.

S-Man42 commented 3 years ago

Thank you: I passed an empty callback, which does the job,

tuarrep commented 3 years ago

@HugoHeneault Could you handle this?

I can help but I can't test right now

HugoHeneault commented 3 years ago

Fixed it. Gonna release 1.3.0 with the fix.