Capitalizing the first letter of a string is a common task in programming, and it's especially useful in Flutter when displaying text to users. This tutorial will show you how to capitalize the first letter of a string in Flutter
String capitalize(String value) {
var result = value[0].toUpperCase();
bool cap = true;
for (int i = 1; i < value.length; i++) {
if (value[i - 1] == " " && cap == true) {
result = result + value[i].toUpperCase();
} else {
result = result + value[i];
cap = false;
}
}
return result;
}
String str1 = capitalize("hello the world.");
print(str1); //Hello the world.
In this way, you can capitalize the first letter of string.