getBarCommand static method

Uint8List? getBarCommand(
  1. String str,
  2. int nVersion,
  3. int nErrorCorrectionLevel,
  4. int nMagnification,
)

Two-dimensional code print function @param str 打印二维码数据 @param nVersion 二维码类型 @param nErrorCorrectionLevel 纠错级别 @param nMagnification 放大倍数 @return

Implementation

static Uint8List? getBarCommand(
  String str,
  int nVersion,
  int nErrorCorrectionLevel,
  int nMagnification,
) {
  if (nVersion < 0 ||
      nVersion > 19 ||
      nErrorCorrectionLevel < 0 ||
      nErrorCorrectionLevel > 3 ||
      nMagnification < 1 ||
      nMagnification > 8) {
    return null;
  }

  final bCodeData = Uint8List.fromList(str.codeUnits);
  final command = Uint8List(bCodeData.length + 7);

  command[0] = 27;
  command[1] = 90;
  command[2] = nVersion;
  command[3] = nErrorCorrectionLevel;
  command[4] = nMagnification;
  command[5] = bCodeData.length & 0xff;
  command[6] = (bCodeData.length & 0xff00) >> 8;

  arraycopy(bCodeData, 0, command, 7, bCodeData.length);
  return command;
}