convert method

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

Implementation

@override
Iterable<bool> convert(String data) sync* {
  data = checkLength(data, maxLength);

  yield* add(BarcodeMaps.eanStartEnd, 3);

  int index = 0;
  for (final int code in data.codeUnits) {
    final List<int>? codes = BarcodeMaps.ean[code];

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

    if (index == 6) {
      yield* add(BarcodeMaps.eanCenter, 5);
    }

    yield* add(codes[index < 6 ? 0 : 2], 7);
    index++;
  }

  yield* add(BarcodeMaps.eanStartEnd, 3);
}