updateField method
Implementation
void updateField() {
String updatedText = widget.controller.text.trim();
// Parse the input: single integer or vector of integers.
List<String> values = updatedText.split(RegExp(r',\s*'));
List<int>? parsedValues = values
.map((e) => int.tryParse(e))
.where((e) => e != null)
.cast<int>()
.toList();
if (parsedValues.isEmpty) {
// If invalid input, leave the field as is.
widget.controller.text = updatedText;
ref.read(widget.stateProvider.notifier).state = updatedText;
} else {
// Update the text field and provider state with parsed values as a string.
widget.controller.text = parsedValues.join(',');
ref.read(widget.stateProvider.notifier).state = widget.controller.text;
}
}