printVal function

String printVal(
  1. dynamic str
)

Implementation

String printVal(str) {
  if (str == '[id_card]' || str.contains('id_card')) {
    return 'ID Card';
  } else if (str == '[credit_or_debit_card]' ||
      str.contains('credit_or_debit_card')) {
    return 'Credit or Debit Card';
  } else if (str == '[passport]' || str.contains('passport')) {
    return 'Passport';
  } else if (str == '[driving_license]' || str.contains('driving_license')) {
    return 'Driving License';
  } else {
    var splitStr = str.toLowerCase().split('_');
    for (var i = 0; i < splitStr.length; i++) {
      if (splitStr[i][0] == '[') {
        splitStr[i] = splitStr[i][1].toUpperCase() + splitStr[i].substring(2);
      } else {
        splitStr[i] = splitStr[i][0].toUpperCase() + splitStr[i].substring(1);
      }
    }
    return splitStr.join(' ');
  }
}