paint method

  1. @override
void paint(
  1. PrettyQrPaintingContext context
)
override

Paints the QR matrix on the canvas of the given painting context.

Implementation

@override
void paint(PrettyQrPaintingContext context) {
  final hasFinderPattern = finderPattern != null;
  final hasTimingPatterns = timingPatterns != null;
  final hasAlignmentPatterns = alignmentPatterns != null;

  if (!hasFinderPattern && !hasTimingPatterns && !hasAlignmentPatterns) {
    shape.paint(context);
    return;
  }

  final matrix = PrettyQrMatrix.masked(
    context.matrix,
    excludeComponents: {
      if (hasFinderPattern) PrettyQrComponentType.finderPattern,
      if (hasTimingPatterns) PrettyQrComponentType.timingPattern,
      if (hasAlignmentPatterns) PrettyQrComponentType.alignmentPattern,
    },
  );
  shape.paint(context.copyWith(matrix: matrix));

  if (hasFinderPattern) {
    finderPattern?.paint(
      context.copyWith(
        matrix: PrettyQrMatrix.masked(
          context.matrix,
          excludeComponents: {
            for (final type in PrettyQrComponentType.values)
              if (type != PrettyQrComponentType.finderPattern) type,
          },
        ),
      ),
    );
  }

  if (hasTimingPatterns) {
    timingPatterns?.paint(
      context.copyWith(
        matrix: PrettyQrMatrix.masked(
          context.matrix,
          excludeComponents: {
            for (final type in PrettyQrComponentType.values)
              if (type != PrettyQrComponentType.timingPattern) type,
          },
        ),
      ),
    );
  }

  if (hasAlignmentPatterns) {
    alignmentPatterns?.paint(
      context.copyWith(
        matrix: PrettyQrMatrix.masked(
          context.matrix,
          excludeComponents: {
            for (final type in PrettyQrComponentType.values)
              if (type != PrettyQrComponentType.alignmentPattern) type,
          },
        ),
      ),
    );
  }
}