createSingleMarker static method

Future<Uint8List> createSingleMarker({
  1. required double dimension,
  2. Color markerColor = Colors.blue,
})

Implementation

static Future<Uint8List> createSingleMarker({
  required double dimension,
  Color markerColor = Colors.blue,
}) async {
  final pictureRecorder = PictureRecorder();
  final canvas = Canvas(pictureRecorder);
  const width = 64;
  const height = 82;
  final markerFill = Paint()
    ..style = PaintingStyle.fill
    ..color = markerColor;
  final paintPath = Path()
    ..moveTo(
      width * 0.01388753,
      height * 0.4148553,
    )
    ..cubicTo(
      width * 0.01388753,
      height * 0.1904737,
      width * 0.2287017,
      height * 0.004386500,
      width * 0.4999983,
      height * 0.004386500,
    )
    ..cubicTo(
      width * 0.7712950,
      height * 0.004386500,
      width * 0.9861100,
      height * 0.1904737,
      width * 0.9861100,
      height * 0.4148553,
    )
    ..cubicTo(
      width * 0.9861100,
      height * 0.4868171,
      width * 0.9408267,
      height * 0.5715553,
      width * 0.8838517,
      height * 0.6510763,
    )
    ..cubicTo(
      width * 0.8259550,
      height * 0.7318842,
      width * 0.7520617,
      height * 0.8125539,
      width * 0.6872750,
      height * 0.8777763,
    )
    ..lineTo(
      width * 0.6851133,
      height * 0.8799513,
    )
    ..cubicTo(
      width * 0.6534917,
      height * 0.9117908,
      width * 0.6265517,
      height * 0.9389145,
      width * 0.6004300,
      height * 0.9576487,
    )
    ..cubicTo(
      width * 0.5719300,
      height * 0.9780868,
      width * 0.5405017,
      height * 0.9914684,
      width * 0.4999983,
      height * 0.9914684,
    )
    ..cubicTo(
      width * 0.4594950,
      height * 0.9914684,
      width * 0.4280683,
      height * 0.9780868,
      width * 0.3995683,
      height * 0.9576487,
    )
    ..cubicTo(
      width * 0.3734450,
      height * 0.9389145,
      width * 0.3465067,
      height * 0.9117921,
      width * 0.3148833,
      height * 0.8799526,
    )
    ..lineTo(
      width * 0.3127233,
      height * 0.8777763,
    )
    ..cubicTo(
      width * 0.2479367,
      height * 0.8125539,
      width * 0.1740417,
      height * 0.7318842,
      width * 0.1161453,
      height * 0.6510763,
    )
    ..cubicTo(
      width * 0.05917117,
      height * 0.5715553,
      width * 0.01388753,
      height * 0.4868171,
      width * 0.01388753,
      height * 0.4148553,
    )
    ..close()
    ..moveTo(
      width * 0.4999983,
      height * 0.2675447,
    )
    ..cubicTo(
      width * 0.3849400,
      height * 0.2675447,
      width * 0.2916650,
      height * 0.3411816,
      width * 0.2916650,
      height * 0.4320184,
    )
    ..cubicTo(
      width * 0.2916650,
      height * 0.5228539,
      width * 0.3849400,
      height * 0.5964921,
      width * 0.4999983,
      height * 0.5964921,
    )
    ..cubicTo(
      width * 0.6150583,
      height * 0.5964921,
      width * 0.7083317,
      height * 0.5228539,
      width * 0.7083317,
      height * 0.4320184,
    )
    ..cubicTo(
      width * 0.7083317,
      height * 0.3411816,
      width * 0.6150583,
      height * 0.2675447,
      width * 0.4999983,
      height * 0.2675447,
    )
    ..close();
  canvas.drawPath(paintPath, markerFill);
  final circleFill = Paint()
    ..style = PaintingStyle.fill
    ..color = ColorName.white;
  const circleOffset = 32.0;
  const circleSize = 15.0;
  canvas.drawCircle(const Offset(circleOffset, circleOffset), circleSize, circleFill);
  final image = await pictureRecorder.endRecording().toImage(
        dimension.toInt(),
        dimension.toInt(),
      );
  final data = await image.toByteData(format: ImageByteFormat.png);
  return data!.buffer.asUint8List();
}