decode function

QrContent? decode(
  1. BitMatrix matrix
)

Decodes a Qr code given the matrix of its raw bits.

Implementation

QrContent? decode(BitMatrix matrix) {
  var result = _readContent(matrix);
  if (result != null) {
    return result;
  }
  // Decoding didn't work, try mirroring the QR across the topLeft -> bottomRight line.
  for (var x = 0; x < matrix.width; x++) {
    for (var y = x + 1; y < matrix.height; y++) {
      if (matrix.get(x, y) != matrix.get(y, x)) {
        matrix.set(x, y, !matrix.get(x, y));
        matrix.set(y, x, !matrix.get(y, x));
      }
    }
  }
  return _readContent(matrix);
}