Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/ui/process_ui/generic_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,16 @@ class _GenericProcessState extends State<GenericProcess>
break;
}
if (globalProvider.isValidBiometricCapture) {
isValid = false;
break;
List<BiometricAttributeData> list = globalProvider.fieldInputValue[field.id!] ?? [];
if (list.isNotEmpty) {
BiometricAttributeData lastCapture = list.last;
if (lastCapture.qualityPercentage < int.parse(lastCapture.thresholdPercentage)) {
isValid = false;
break;
}
}
}
Comment on lines +526 to 534
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling for threshold parsing.

int.parse() will throw a FormatException if thresholdPercentage is not a valid integer string or if it's null. This can crash the validation flow.

🔎 Apply this diff to add safe parsing with error handling:
 if (globalProvider.isValidBiometricCapture) {
   List<BiometricAttributeData> list = globalProvider.fieldInputValue[field.id!] ?? [];
   if (list.isNotEmpty) {
     BiometricAttributeData lastCapture = list.last;
-    if (lastCapture.qualityPercentage < int.parse(lastCapture.thresholdPercentage)) {
+    int? threshold = int.tryParse(lastCapture.thresholdPercentage);
+    if (threshold != null && lastCapture.qualityPercentage < threshold) {
       isValid = false;
       break;
     }
   }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
List<BiometricAttributeData> list = globalProvider.fieldInputValue[field.id!] ?? [];
if (list.isNotEmpty) {
BiometricAttributeData lastCapture = list.last;
if (lastCapture.qualityPercentage < int.parse(lastCapture.thresholdPercentage)) {
isValid = false;
break;
}
}
}
List<BiometricAttributeData> list = globalProvider.fieldInputValue[field.id!] ?? [];
if (list.isNotEmpty) {
BiometricAttributeData lastCapture = list.last;
int? threshold = int.tryParse(lastCapture.thresholdPercentage);
if (threshold != null && lastCapture.qualityPercentage < threshold) {
isValid = false;
break;
}
}
}
🤖 Prompt for AI Agents
In lib/ui/process_ui/generic_process.dart around lines 526 to 534, the code uses
int.parse(lastCapture.thresholdPercentage) which can throw FormatException or
NPE if thresholdPercentage is null; change this to use safe parsing (int? parsed
= int.tryParse(lastCapture.thresholdPercentage ?? '');) and handle the
null/failed-parse case by treating the capture as invalid (set isValid = false;
break) and optionally log or record the malformed threshold for diagnostics;
ensure no exceptions propagate from parsing so the validation flow continues
safely.


}
}
}
Expand Down Expand Up @@ -565,9 +572,16 @@ class _GenericProcessState extends State<GenericProcess>
break;
}
if (globalProvider.isValidBiometricCapture) {
isValid = false;
break;
List<BiometricAttributeData> list = globalProvider.fieldInputValue[field.id!] ?? [];
if (list.isNotEmpty) {
BiometricAttributeData lastCapture = list.last;
if (lastCapture.qualityPercentage < int.parse(lastCapture.thresholdPercentage)) {
isValid = false;
break;
}
}
}

Comment on lines +575 to +584
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Extract duplicated validation logic into a helper method.

This quality validation block is identical to the one at lines 526-534. Duplicate logic increases maintenance burden and bug risk.

🔎 View suggested refactor to eliminate duplication:

Add this helper method to the class:

bool _isLastCaptureQualityValid(String fieldId) {
  List<BiometricAttributeData> list = globalProvider.fieldInputValue[fieldId] ?? [];
  if (list.isEmpty) return true;
  
  BiometricAttributeData lastCapture = list.last;
  int? threshold = int.tryParse(lastCapture.thresholdPercentage);
  if (threshold == null) return true; // or false, depending on policy
  
  return lastCapture.qualityPercentage >= threshold;
}

Then replace both occurrences with:

 if (globalProvider.isValidBiometricCapture) {
-  List<BiometricAttributeData> list = globalProvider.fieldInputValue[field.id!] ?? [];
-  if (list.isNotEmpty) {
-    BiometricAttributeData lastCapture = list.last;
-    if (lastCapture.qualityPercentage < int.parse(lastCapture.thresholdPercentage)) {
-      isValid = false;
-      break;
-    }
-  }
+  if (!_isLastCaptureQualityValid(field.id!)) {
+    isValid = false;
+    break;
+  }
 }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In lib/ui/process_ui/generic_process.dart around lines 526-534 and 575-584 there
is duplicated last-capture quality validation; extract that logic into a private
helper on the class (e.g. _isLastCaptureQualityValid) that takes the fieldId,
fetches the list from globalProvider.fieldInputValue[fieldId] using a default
empty list, returns true if empty, safely parses threshold with int.tryParse and
returns true on parse failure (or adjust to project policy), and compares
lastCapture.qualityPercentage >= threshold; then replace both duplicated blocks
with a single call to this helper.

}
}
if (response.compareTo(
Expand Down