Skip to content

Commit

Permalink
Add markerChildBehavior option to MarkerWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinisSprogis committed Feb 22, 2024
1 parent 9c4fb8c commit 7f56347
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/src/marker_cluster_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ class _MarkerClusterLayerState extends State<MarkerClusterLayer>
key: marker.key ?? ObjectKey(marker.marker),
child: MarkerWidget(
marker: marker,
markerChildBehavior: widget.options.markerChildBehavior,
onTap: _onMarkerTap(marker),
onHover: (bool value) => _onMarkerHover(marker, value),
buildOnHover: widget.options.popupOptions?.buildPopupOnHover ?? false,
Expand Down
9 changes: 9 additions & 0 deletions lib/src/marker_cluster_layer_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ class MarkerClusterLayerOptions {
/// Function to call when a cluster Marker is tapped
final void Function(MarkerClusterNode)? onClusterTap;


///If set to [true] the marker will have only gesture behavior that is provided by the marker child.
///Can be used in cases where the marker child is a widget that already has gesture behavior and [GestureDetector] from the [MarkerClusterLayer] is interfering with it.
///If set to [true] [onMarkerTap] [onMarkerHoverEnter] [onMarkerHoverExit] [centerMarkerOnClick] will not work.
///
///Defaults to [false].
final bool markerChildBehavior;

/// Popup's options that show when tapping markers or via the PopupController.
final PopupOptions? popupOptions;

Expand Down Expand Up @@ -210,5 +218,6 @@ class MarkerClusterLayerOptions {
this.onClusterTap,
this.onMarkersClustered,
this.popupOptions,
this.markerChildBehavior = false,
});
}
26 changes: 15 additions & 11 deletions lib/src/marker_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,30 @@ class MarkerWidget extends StatelessWidget {
final VoidCallback onTap;
final Function(bool)? onHover;
final bool buildOnHover;
final bool markerChildBehavior;

MarkerWidget({
required this.marker,
required this.onTap,
required this.markerChildBehavior,
this.onHover,
this.buildOnHover = false,
}) : super(key: marker.key ?? ObjectKey(marker.marker));

@override
Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: buildOnHover && onHover != null
? MouseRegion(
onEnter: (_) => onHover!(true),
onExit: (_) => onHover!(false),
child: marker.child,
)
: marker.child,
);
return markerChildBehavior
? marker.child
: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: buildOnHover && onHover != null
? MouseRegion(
onEnter: (_) => onHover!(true),
onExit: (_) => onHover!(false),
child: marker.child,
)
: marker.child,
);
}
}

0 comments on commit 7f56347

Please sign in to comment.