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);
  int iData;
  try {
    iData = int.parse(data);
  } catch (e) {
    throw BarcodeException('Unable to encode "$data" to $name Barcode');
  }
  final pattern = iData % 4;

  // 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) ^ 1], 7);
    index++;
  }
}