getTextInputFormatters method

List<TextInputFormatter>? getTextInputFormatters(
  1. Map? spec
)

Implementation

List<TextInputFormatter>? getTextInputFormatters(Map? spec) {
  if (spec == null || spec.isEmpty) {
    return null;
  }

  final list = <TextInputFormatter>[];
  if (spec["allow"] != null) {
    list.add(FilteringTextInputFormatter.allow(RegExp(spec["allow"])));
  }
  if (spec["deny"] != null) {
    list.add(FilteringTextInputFormatter.deny(RegExp(spec["deny"])));
  }
  if (spec["mask"] != null) {
    Map<String, RegExp>? maskFilter;
    String? maskFilterValue = spec["maskFilter"];
    if (maskFilterValue != null) {
      maskFilter = {};
      final filters = maskFilterValue.split(RegExp(r'[|\s]'));
      for (var filter in filters) {
        var parts = filter.split(":");
        if (parts.length > 1) {
          maskFilter[parts[0].trim()] = RegExp(parts[1].trim());
        } else {
          maskFilter["#"] = RegExp(parts[0].trim());
        }
      }
    }
    list.add(MaskTextInputFormatter(mask: spec["mask"], filter: maskFilter));
  }
  return list;
}