properCase static method

String properCase(
  1. String sentence
)

Converts sentence to proper case by capitalising the first letter of each word and forcing all other characters to lower case.

Implementation

static String properCase(String sentence) {
  var words = sentence.split(' ');
  var result = '';

  for (var word in words) {
    var lower = word.toLowerCase();
    if (lower.isNotEmpty) {
      var proper =
          '${lower.substring(0, 1).toUpperCase()}${lower.substring(1)}';
      result = result.isEmpty ? proper : '$result $proper';
    }
  }
  return result;
}