createLocationMarkerIcon2 function

Future<BitmapDescriptor> createLocationMarkerIcon2(
  1. double size,
  2. Color color
)

Implementation

Future<BitmapDescriptor> createLocationMarkerIcon2(double size, Color color) async {
  final PictureRecorder pictureRecorder = PictureRecorder();
  final Canvas canvas = Canvas(pictureRecorder);

  final double centerX = size / 2;
  final double centerY = size / 2;
  final double radius = size / 2;

  final Paint circlePaint = Paint()..color = color;
  canvas.drawCircle(Offset(centerX, centerY), radius, circlePaint);

  final Paint innerCirclePaint = Paint()..color = Colors.white;
  canvas.drawCircle(Offset(centerX, centerY), radius - 4, innerCirclePaint);

  final Paint markerPaint = Paint()..color = color;
  canvas.drawRect(Rect.fromLTWH(centerX - 2, centerY + 8, 4, size - 8), markerPaint);

  final ui.Picture picture = pictureRecorder.endRecording();
  final ui.Image image = await picture.toImage(size.toInt(), size.toInt());
  final ByteData? byteData = await image.toByteData(format: ui.ImageByteFormat.png);
  final Uint8List data = byteData!.buffer.asUint8List();

  return BitmapDescriptor.fromBytes(data);
}