formatName static method

String formatName(
  1. String text, {
  2. dynamic type = "text",
})

Implementation

static String formatName(String text, {type = "text"}) {
  if (text == "" || text == null) return "";
  if (type == 'phone') {
    return text.replaceFirst(new RegExp(r'\d{4}'), '****', 3);
  } else {
    if (text.length > 2) {
      return text.replaceFirst(new RegExp('.'), '*', 1);
    }
    return text.substring(0, 1) + '*';
  }
}