Skip to content
Open
Show file tree
Hide file tree
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
53 changes: 24 additions & 29 deletions lib/ui/process_ui/widgets/pre_reg_data_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,36 +251,31 @@ class _PreRegDataControlState extends State<PreRegDataControl> {
children: [
Expanded(
flex: 3,
child: Semantics(
label: 'application_id_text_field',
container: true,
excludeSemantics: true,
child: TextFormField(
key: _formFieldKey,
controller: preRegIdController,
autovalidateMode: AutovalidateMode.onUserInteraction,
textCapitalization: TextCapitalization.words,
onChanged: (value) {
globalProvider.setPreRegistrationId(value);
},
validator: (value) {
if (value == null || value.isEmpty) return null;
if (globalProvider.pridLength != null &&
value.length > globalProvider.pridLength!) {
return AppLocalizations.of(context)!
.prid_length_greater(globalProvider.pridLength!);
}
return null;
},
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
hintText:
AppLocalizations.of(context)!.enter_application_id,
child: TextFormField(
key: _formFieldKey,
controller: preRegIdController,
autovalidateMode: AutovalidateMode.onUserInteraction,
textCapitalization: TextCapitalization.words,
onChanged: (value) {
globalProvider.setPreRegistrationId(value);
},
validator: (value) {
if (value == null || value.isEmpty) return null;
if (globalProvider.pridLength != null &&
value.length > globalProvider.pridLength!) {
return AppLocalizations.of(context)!
.prid_length_greater(globalProvider.pridLength!);
}
return null;
Comment on lines +262 to +269
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

Make the field validator match the fetch-time rules.

This validator only rejects values longer than pridLength. Short or non-numeric IDs still pass validate(), so the fetch handler proceeds into the invalid-ID branch and its side effects. Mirror the exact-length + digits check here.

Possible fix
                 validator: (value) {
                   if (value == null || value.isEmpty) return null;
-                  if (globalProvider.pridLength != null &&
-                      value.length > globalProvider.pridLength!) {
-                    return AppLocalizations.of(context)!
-                        .prid_length_greater(globalProvider.pridLength!);
+                  final pridLength = globalProvider.pridLength;
+                  if (pridLength != null &&
+                      (value.length != pridLength ||
+                          !RegExp(r'^\d+$').hasMatch(value))) {
+                    return AppLocalizations.of(context)!.correct_application_id;
                   }
                   return null;
                 },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/ui/process_ui/widgets/pre_reg_data_control.dart` around lines 262 - 269,
The validator for the ID field currently only checks for length > pridLength and
lets short or non-numeric values pass; update the validator closure in
pre_reg_data_control.dart (the validator used in the widget at/around the
validator: (value) { ... } block) to enforce exact-length and numeric-only
rules: if globalProvider.pridLength is set, require value.length ==
globalProvider.pridLength and that value matches a digits-only pattern (e.g.,
regex for exactly N digits); return the existing localized error message (or a
new localized message) when the value fails these checks and return null only
when it exactly matches the required digit count. Ensure you reference
globalProvider.pridLength and AppLocalizations in the updated validator.

},
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
hintText:
AppLocalizations.of(context)!.enter_application_id,
),
),
),
Expand Down
153 changes: 74 additions & 79 deletions lib/ui/process_ui/widgets/textbox_control.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,91 +167,86 @@ class _TextBoxControlState extends State<TextBoxControl>
controllerMap.putIfAbsent(lang,
() => TextEditingController(text: _getDataFromMap(lang)));
});
return Semantics(
label: '${widget.e.id}',
container: true,
excludeSemantics: true,
child: Container(
margin: const EdgeInsets.only(bottom: 8),
child: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: controllerMap[lang],
textCapitalization: TextCapitalization.words,
onChanged: (value) async {
if (lang == mandatoryLanguageCode) {
for (var target in choosenLang) {
String targetCode = globalProvider.langToCode(target);
if (targetCode != mandatoryLanguageCode) {
log("$mandatoryLanguageCode ----> $targetCode");
try {
String result = await TransliterationServiceImpl()
.transliterate(TransliterationOptions(
input: value,
sourceLanguage: "Any",
targetLanguage: tranliterationLangMapper[
targetCode] ??
targetCode.substring(0, 2)));
_saveDataToMap(result, targetCode);
saveData(result, targetCode);
setState(() {
controllerMap[targetCode]!.text = result;
});
log("Transliteration success : $result");
} catch (e) {
log("Transliteration failed : $e");
}
return Container(
margin: const EdgeInsets.only(bottom: 8),
child: TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: controllerMap[lang],
textCapitalization: TextCapitalization.words,
onChanged: (value) async {
if (lang == mandatoryLanguageCode) {
for (var target in choosenLang) {
String targetCode = globalProvider.langToCode(target);
if (targetCode != mandatoryLanguageCode) {
log("$mandatoryLanguageCode ----> $targetCode");
try {
String result = await TransliterationServiceImpl()
.transliterate(TransliterationOptions(
input: value,
sourceLanguage: "Any",
targetLanguage: tranliterationLangMapper[
targetCode] ??
targetCode.substring(0, 2)));
_saveDataToMap(result, targetCode);
saveData(result, targetCode);
setState(() {
controllerMap[targetCode]!.text = result;
});
log("Transliteration success : $result");
} catch (e) {
log("Transliteration failed : $e");
}
}
}
_saveDataToMap(value, lang);
saveData(value, lang);
},
validator: (value) {
if (!widget.e.required!) {
if (widget.e.requiredOn == null ||
widget.e.requiredOn!.isEmpty ||
!(globalProvider.mvelRequiredFields[widget.e.id] ??
true)) {
if (value == null || value.isEmpty) {
return null;
} else if (!widget.validation.hasMatch(value)) {
return AppLocalizations.of(context)!.invalid_input;
}
}
_saveDataToMap(value, lang);
saveData(value, lang);
},
Comment on lines +176 to +204
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

Ignore stale transliteration responses.

Each keystroke starts async transliteration work and then blindly writes the awaited result into the target controllers. If an older request finishes last, it can overwrite newer input and persist stale demographics.

Possible fix
 class _TextBoxControlState extends State<TextBoxControl>
     with WidgetsBindingObserver {
   bool isMvelValid = true;
   Map<String, TextEditingController> controllerMap = {};
   late GlobalProvider globalProvider;
   late RegistrationTaskProvider registrationTaskProvider;
+  int _transliterationRequestId = 0;
@@
                   onChanged: (value) async {
+                    final requestId = ++_transliterationRequestId;
                     if (lang == mandatoryLanguageCode) {
                       for (var target in choosenLang) {
                         String targetCode = globalProvider.langToCode(target);
                         if (targetCode != mandatoryLanguageCode) {
@@
                             String result = await TransliterationServiceImpl()
                                 .transliterate(TransliterationOptions(
                                     input: value,
                                     sourceLanguage: "Any",
                                     targetLanguage: tranliterationLangMapper[
                                             targetCode] ??
                                         targetCode.substring(0, 2)));
+                            if (!mounted ||
+                                requestId != _transliterationRequestId ||
+                                controllerMap[lang]?.text != value) {
+                              continue;
+                            }
                             _saveDataToMap(result, targetCode);
                             saveData(result, targetCode);
                             setState(() {
                               controllerMap[targetCode]!.text = result;
                             });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/ui/process_ui/widgets/textbox_control.dart` around lines 176 - 204, The
onChanged handler launches async transliteration for each target and directly
writes awaited results into controllerMap and saves them, allowing stale
responses to overwrite newer input; fix by introducing a per-input request token
or incrementing requestId (scoped to this widget) before calling
TransliterationServiceImpl().transliterate and, after awaiting, verify the
token/requestId still matches the latest value before calling _saveDataToMap,
saveData, or updating controllerMap[targetCode]!.text; reference the onChanged
closure, TransliterationServiceImpl().transliterate call,
controllerMap[targetCode]!.text updates, and _saveDataToMap/saveData calls to
add this guard so only the most recent transliteration result is applied.

validator: (value) {
if (!widget.e.required!) {
if (widget.e.requiredOn == null ||
widget.e.requiredOn!.isEmpty ||
!(globalProvider.mvelRequiredFields[widget.e.id] ??
true)) {
if (value == null || value.isEmpty) {
return null;
} else if (!widget.validation.hasMatch(value)) {
return AppLocalizations.of(context)!.invalid_input;
}
}
// if (!widget.e.required! &&
// (widget.e.requiredOn == null ||
// widget.e.requiredOn!.isEmpty)) {
// if (value == null || value.isEmpty) {
// return null;
// } else if (!widget.validation.hasMatch(value)) {
// return AppLocalizations.of(context)!.invalid_input;
// }
// }
if (value == null || value.isEmpty) {
return AppLocalizations.of(context)!
.enter_value_message;
}
if (!widget.validation.hasMatch(value)) {
return AppLocalizations.of(context)!.invalid_input;
}
return null;
},
textAlign: Bidi.isRtlLanguage(lang.substring(0, 2))
? TextAlign.right
: TextAlign.left,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide:
const BorderSide(color: appGreyShade, width: 1),
),
contentPadding: const EdgeInsets.symmetric(
vertical: 14, horizontal: 16),
hintText: widget.e.label![lang],
hintStyle:
const TextStyle(color: appBlackShade3, fontSize: 14),
}
// if (!widget.e.required! &&
// (widget.e.requiredOn == null ||
// widget.e.requiredOn!.isEmpty)) {
// if (value == null || value.isEmpty) {
// return null;
// } else if (!widget.validation.hasMatch(value)) {
// return AppLocalizations.of(context)!.invalid_input;
// }
// }
if (value == null || value.isEmpty) {
return AppLocalizations.of(context)!
.enter_value_message;
}
if (!widget.validation.hasMatch(value)) {
return AppLocalizations.of(context)!.invalid_input;
}
return null;
},
textAlign: Bidi.isRtlLanguage(lang.substring(0, 2))
? TextAlign.right
: TextAlign.left,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide:
const BorderSide(color: appGreyShade, width: 1),
),
contentPadding: const EdgeInsets.symmetric(
vertical: 14, horizontal: 16),
hintText: widget.e.label![lang],
hintStyle:
const TextStyle(color: appBlackShade3, fontSize: 14),
),
),
);
Expand Down