scanBitMatrix method
dynamic
scanBitMatrix(})
Scan a BitMatrix to update QR code content and location.
Implementation
scanBitMatrix(
BitMatrix matrix, {
bool invalidateContent = false,
bool ignoreIfUnreadable = false,
bool perfectQrCode = false,
}) {
// Keep old content as default, unless stale or forceDecode is true
QrContent? newContent;
// Get new location
// TODO: Evaluate whether the new location is realistic
// Consider using the old location instead or interpolating
final newLocation = locate(matrix, perfectQrCode: perfectQrCode);
if (newLocation != null) {
newContent = decode(_extract(matrix, newLocation));
}
// Handle content caching
if (invalidateContent || _staleCounter >= contentCacheLimit) {
_staleCounter = 0;
} else {
// If content could not be decoded, keep the old value
if (newContent == null) {
newContent = _content;
}
_staleCounter++;
}
// If the ignoreIfUnreadable flag is set, and the content could not be
// decoded, do not update the content nor the location.
if (ignoreIfUnreadable) {
if (newContent == null) {
return;
}
}
// Update content and location
_content = newContent;
_location = newLocation;
}