makeBytes method

  1. @override
Iterable<BarcodeElement> makeBytes(
  1. Uint8List data, {
  2. required double width,
  3. required double height,
  4. bool drawText = false,
  5. double? fontHeight,
  6. double? textPadding,
})
inherited

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);
  }
}