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 ??= defaultTextPadding;
final text = utf8.decoder.convert(data);
final bits = convert(text).toList();
if (bits.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) / bits.length;
var color = bits.first;
var count = 1;
for (var i = 1; i < bits.length; i++) {
if (color == bits[i]) {
count++;
continue;
}
yield BarcodeBar(
left: left + (i - count) * lineWidth,
top: top,
width: count * lineWidth,
height: getHeight(
i - count,
count,
width,
height - top,
fontHeight,
textPadding,
drawText,
),
black: color,
);
color = bits[i];
count = 1;
}
final l = bits.length;
yield BarcodeBar(
left: left + (l - count) * lineWidth,
top: top,
width: count * lineWidth,
height: getHeight(
l - count,
count,
width,
height - top,
fontHeight,
textPadding,
drawText,
),
black: color,
);
if (drawText) {
yield* makeText(text, width, height, fontHeight, textPadding, lineWidth);
}
}