buildClusterMarker property

(Future<Marker> Function(Cluster<Place> cluster)?) buildClusterMarker
final

To draw the marker on Map when showMarkerClusters is set to true.

For example,

// Function to build icon
Future<BitmapDescriptor> _getMarkerBitmap(int size, {String? text}) async {
  if (kIsWeb) size = (size / 2).floor();

  final PictureRecorder pictureRecorder = PictureRecorder();
  final Canvas canvas = Canvas(pictureRecorder);
  final Paint paint1 = Paint()..color = Colors.orange;
  final Paint paint2 = Paint()..color = Colors.white;

  canvas.drawCircle(Offset(size / 2, size / 2), size / 2.0, paint1);
  canvas.drawCircle(Offset(size / 2, size / 2), size / 2.2, paint2);
  canvas.drawCircle(Offset(size / 2, size / 2), size / 2.8, paint1);

  if (text != null) {
    TextPainter painter = TextPainter(textDirection: TextDirection.ltr);
   painter.text = TextSpan(
     text: text,
     style: TextStyle(
        fontSize: size / 3,
        color: Colors.white,
        fontWeight: FontWeight.normal),
  );
  painter.layout();
  painter.paint(
    canvas,
    Offset(size / 2 - painter.width / 2, size / 2 - painter.height / 2),
  );
 }

 final img = await pictureRecorder.endRecording().toImage(size, size);
 final data = await img.toByteData(format: ImageByteFormat.png) as ByteData;
  return BitmapDescriptor.fromBytes(data.buffer.asUint8List());
}

// Define `buildClusterMarker` in [RecativeGoogleMap]
buildClusterMarker: (Cluster cluster) async {
    return Marker(
            markerId: MarkerId(cluster.getId()),
            position: cluster.location,
            icon: await _getMarkerBitmap(cluster.isMultiple ? 125 : 75,
            text:
              cluster.isMultiple ? cluster.count.toString() : null),
     );
 }
```dart

Implementation

///   return BitmapDescriptor.fromBytes(data.buffer.asUint8List());
/// }
///
/// // Define `buildClusterMarker` in [RecativeGoogleMap]
/// buildClusterMarker: (Cluster cluster) async {
///     return Marker(
///             markerId: MarkerId(cluster.getId()),
///             position: cluster.location,
///             icon: await _getMarkerBitmap(cluster.isMultiple ? 125 : 75,
///             text:
///               cluster.isMultiple ? cluster.count.toString() : null),
///      );
///  }
/// ```dart
final Future<Marker> Function(Cluster<Place> cluster)? buildClusterMarker;