inputFormatters static method
Implementation
static List<TextInputFormatter>? inputFormatters(dynamic value) {
if (value is! List) return null;
final formatters = <TextInputFormatter>[];
for (final item in value) {
if (item is! Map) continue;
final type = item['type'];
final regexString = item['regex'];
if (regexString == null ||
regexString is! String ||
regexString.isEmpty) {
continue;
}
try {
final regex = RegExp(regexString);
if (type == 'allow') {
formatters.add(FilteringTextInputFormatter.allow(regex));
} else if (type == 'deny') {
formatters.add(FilteringTextInputFormatter.deny(regex));
}
} on FormatException catch (e) {
debugPrint('Invalid regex pattern "$regexString": $e');
}
}
return formatters.isEmpty ? null : formatters;
}