2024年4月22日发(作者:)

return Size(ratio * , ratio * );

} else {

final maxSide = 0.25 * stSide;

final ratio = maxSide / tSide;

return Size(ratio * , ratio * );

}

}

bool _isFinderPatternPosition(int x, int y) {

final isTopLeft = (y < _finderPatternLimit && x < _finderPatternLimit);

final isBottomLeft = (y < _finderPatternLimit &&

(x >= _Count - _finderPatternLimit));

final isTopRight = (y >= _Count - _finderPatternLimit &&

(x < _finderPatternLimit));

return isTopLeft || isBottomLeft || isTopRight;

}

bool _hasOneNonZeroSide(Size size) => tSide > 0;

void _drawFinderPatternItem(

FinderPatternPosition position,

Canvas canvas,

_PaintMetrics metrics,

) {

final totalGap = (_finderPatternLimit - 1) * e;

final radius = ((_finderPatternLimit * ize) + totalGap) -

ize;

final strokeAdjust = (ize / 2.0);

final edgePos =

( + ontentSize) - (radius + strokeAdjust);

Offset offset;

if (position == t) {

offset =

Offset( + strokeAdjust, + strokeAdjust);

} else if (position == Left) {

offset = Offset( + strokeAdjust, edgePos);

} else {

offset = Offset(edgePos, + strokeAdjust);

}

// configure the paints

final outerPaint = _aint(PatternOuter,

position: position);

Width = ize;

= color;

final innerPaint = _aint(PatternInner,

position: position);

Width = ize;

= emptyColor ?? Color(0x00ffffff);

final dotPaint = _aint(PatternDot,

position: position);

= color;

final outerRect = WH(, , radius, radius);

ct(outerRect, outerPaint);

final innerRadius = radius - (2 * ize);

final innerRect = WH( + ize,

+ ize, innerRadius, innerRadius);

ct(innerRect, innerPaint);

final gap = ize * 2;

final dotSize = radius - gap - (2 * strokeAdjust);

final dotRect = WH( + ize + strokeAdjust,

+ ize + strokeAdjust, dotSize, dotSize);

ct(dotRect, dotPaint);

}

void _drawImageOverlay(

Canvas canvas, Offset position, Size size, QrEmbeddedImageStyle style) {

final paint = Paint()

..isAntiAlias = true

..filterQuality = ;

if (style != null) {

if ( != null) {

ilter = (, p);

}

}

final srcSize =

Size(le(), le());

final src = be(srcSize, & srcSize);

final dst = be(size, position & size);

ageRect(embeddedImage, src, dst, paint);

}

void _init(String data) {

if (!ortedVersion(version)) {

throw QrUnsupportedVersionException(version);

}

// configure and make the QR code data

final validationResult = te(

data: data,

version: version,

errorCorrectionLevel: errorCorrectionLevel,

);

if (!d) {

throw ;

}

_qr = ;

_calcVersion = _mber;

_initPaints();

}

void _initPaints() {

// Cache the pixel paint object. For now there is only one but we might

// expand it to multiple later (e.g.: different colours).

_(

Paint()..style = , xel);

// Cache the empty pixel paint object. Empty color is deprecated and will go

// away.

_(

Paint()..style = , xelEmpty);

// Cache the finder pattern painters. We'll keep one for each one in case

// we want to provide customization options later.

for (final position in ) {

_(Paint()..style = ,

PatternOuter,

position: position);

_(Paint()..style = ,

PatternInner,

position: position);

_(

Paint()..style = , PatternDot,

position: position);

}

}