drawAvatar method

Future<Uint8List?> drawAvatar(
  1. BuildContext context
)

Implementation

Future<Uint8List?> drawAvatar(BuildContext context) async{
  final PictureRecorder pictureRecorder = PictureRecorder();
  final Canvas canvas = Canvas(pictureRecorder);
  final densityPixel = MediaQuery.of(context).devicePixelRatio;

  if(!isNullOrEmpty(imagePath)) {
    try {
      final image = await _loadImage(imagePath);

      NUIAvatarMarkerCustomPainter painter = NUIAvatarMarkerCustomPainter(
          color: color,
          outlineColor: outlineColor,
          thickness: thickness * densityPixel,
          image: image,
          shadowRadius: shadowRadius * densityPixel,
          shadowColor: shadowColor,
          textSpan: textSpan,
          textBackground: textBackground,
          densityRatio: densityPixel
      );

      painter.paint(canvas, Size(size * densityPixel, size * densityPixel));
    } catch (e) {
      logNUI("NUIMapMarkerRenderer", "Failed to load image with error : $e");
    }
  }
  else{
    NUIAvatarMarkerCustomPainter painter = NUIAvatarMarkerCustomPainter(
        color: color,
        outlineColor: outlineColor,
        thickness: thickness * densityPixel,
        shadowRadius: shadowRadius * densityPixel,
        shadowColor: shadowColor,
        textSpan: textSpan,
        textBackground: textBackground,
        densityRatio: densityPixel
    );

    painter.paint(canvas, Size(size * densityPixel, size * densityPixel));
  }

  final picture = pictureRecorder.endRecording();
  final pngBytes = await (await picture.toImage((size * densityPixel).toInt(), (size * densityPixel).toInt())).toByteData(format: ui.ImageByteFormat.png);

  return pngBytes?.buffer.asUint8List();
}