convert method

  1. @override
Iterable<bool> convert(
  1. String data
)
override

Actual barcode computation method, returns a stream of bool which represents the presence or absence of a bar

Implementation

@override
Iterable<bool> convert(String data) sync* {
  final startStop = <int>[0x41, 0x42, 0x43, 0x44];

  var lStart = startStop[start.index];
  var lStop = startStop[stop.index];

  if (explicitStartStop) {
    lStart = _getStartStopByte(data.codeUnitAt(0));
    lStop = _getStartStopByte(data.codeUnitAt(data.length - 1));
    data = data.substring(1, data.length - 1);
  }

  // Start
  yield* add(BarcodeMaps.codabar[lStart]!, BarcodeMaps.codabarLen[lStart]!);

  // Space between chars
  yield false;

  for (var code in data.codeUnits) {
    if (code > 0x40 || code == 0x2a) {
      throw BarcodeException(
          'Unable to encode "${String.fromCharCode(code)}" to $name Barcode');
    }

    final codeValue = BarcodeMaps.codabar[code];
    if (codeValue == null) {
      throw BarcodeException(
          'Unable to encode "${String.fromCharCode(code)}" to $name Barcode');
    }
    final codeLen = BarcodeMaps.codabarLen[code]!;
    yield* add(codeValue, codeLen);

    // Space between chars
    yield false;
  }

  // Stop
  yield* add(BarcodeMaps.codabar[lStop]!, BarcodeMaps.codabarLen[lStop]!);
}