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* {
  verify(data);
  final checksum = checkSumModulo10(data);
  final pattern = BarcodeMaps.ean5Checksum[checksum.codeUnitAt(0)];

  // Start
  yield* add(BarcodeMaps.eanStartEan2, 5);

  var index = 0;
  for (var code in data.codeUnits) {
    final codes = BarcodeMaps.ean[code];

    if (codes == null) {
      throw BarcodeException(
          'Unable to encode "${String.fromCharCode(code)}" to $name Barcode');
    }

    if (index >= 1) {
      yield* add(BarcodeMaps.eanCenterEan2, 2);
    }

    yield* add(codes[(pattern! >> index) & 1], 7);
    index++;
  }
}