generateResult method
Launches the module result search then updates the list of old results
Implementation
Future<List<ScanMatchCounter>> generateResult(
List<ml_kit.TextBlock> textBlock,
String text,
Size imageSize,
) async {
if (_busyGenerated) {
return matchedCounterList;
}
_busyGenerated = true;
List<ScanResult> newScanResult = await matchedResult(
_convertTextBlocks(
textBlock,
imageSize,
),
text,
);
/// We update the visibility counters of the MatchedCounter objects:
/// - If still present in the new list, we up the counter
/// - If not present, we down the counter and we delete if no longer visible
List<ScanMatchCounter> matchedCounterListUpdated = [];
for (var element in matchedCounterList) {
bool found = false;
for (var scanResult in newScanResult) {
if (_matchedStringAndPosition(element.scanResult, scanResult)) {
found = true;
element.scanResult = scanResult;
element.upCounter();
}
}
if (!found) {
element.downCounter();
}
if (element.visible) {
matchedCounterListUpdated.add(element);
}
}
matchedCounterList = matchedCounterListUpdated;
/// We add the new unknown values in matchedCounterList
for (var scanResult in newScanResult) {
bool found = false;
for (var element in matchedCounterList) {
if (_matchedStringAndPosition(element.scanResult, scanResult)) {
found = true;
}
}
if (!found) {
matchedCounterList.add(
ScanMatchCounter(
scanResult: scanResult,
validateCountCorrelation: validateCountCorrelation,
color: color,
),
);
}
}
_busyGenerated = false;
return matchedCounterList;
}