capitalize method
Capitalizes the first letter of each word and lowercases the rest.
Example:
'hello WORLD'.capitalize(); // returns 'Hello World'
Implementation
String capitalize() {
return split(RegExp(r'\s+'))
.where((word) => word.isNotEmpty)
.map((word) => word[0].toUpperCase() + word.substring(1).toLowerCase())
.join(' ');
}