makeBytes method
Iterable<BarcodeElement>
makeBytes(
- Uint8List data, {
- required double width,
- required double height,
- bool drawText = false,
- double? fontHeight,
- double? textPadding,
override
Generate the barcode graphic description like make but takes a Uint8List data.
Implementation
@override
Iterable<BarcodeElement> makeBytes(
Uint8List data, {
required double width,
required double height,
bool drawText = false,
double? fontHeight,
double? textPadding,
}) sync* {
assert(width > 0);
assert(height > 0);
assert(!drawText || fontHeight != null);
fontHeight ??= 0;
textPadding ??= Barcode1D.defaultTextPadding;
final text = utf8.decoder.convert(data);
final bars = convertHM(text).toList();
if (bars.isEmpty) {
return;
}
final top = marginTop(
drawText,
width,
height,
fontHeight,
textPadding,
);
final left = marginLeft(
drawText,
width,
height,
fontHeight,
textPadding,
);
final right = marginRight(
drawText,
width,
height,
fontHeight,
textPadding,
);
final lineWidth = (width - left - right) / (bars.length * 2 - 1);
var index = 0;
final barHeight = height - (drawText ? fontHeight + textPadding : 0) - top;
final tracker = barHeight * _tracker;
for (final bar in bars) {
switch (bar) {
case BarcodeHMBar.tracker:
yield BarcodeBar(
left: left + (index * 2) * lineWidth,
top: top + barHeight / 2 - tracker / 2,
width: lineWidth,
height: tracker,
black: true,
);
break;
case BarcodeHMBar.ascender:
yield BarcodeBar(
left: left + (index * 2) * lineWidth,
top: top,
width: lineWidth,
height: barHeight / 2 + tracker / 2,
black: true,
);
break;
case BarcodeHMBar.descender:
yield BarcodeBar(
left: left + (index * 2) * lineWidth,
top: top + barHeight / 2 - tracker / 2,
width: lineWidth,
height: barHeight / 2 + tracker / 2,
black: true,
);
break;
case BarcodeHMBar.full:
yield BarcodeBar(
left: left + (index * 2) * lineWidth,
top: top,
width: lineWidth,
height: barHeight,
black: true,
);
break;
}
index++;
}
if (drawText) {
yield* makeText(text, width, height, fontHeight, textPadding, lineWidth);
}
}