toTitleCase function

String toTitleCase(
  1. String str
)

Implementation

String toTitleCase(String str) {
  return str.trim().replaceAllMapped(RegExp(r'\w\S*'), (match) {
    final txt = match.group(0)!;
    return txt[0].toUpperCase() + txt.substring(1).toLowerCase();
  });
}