In Flutter, how would you capitalize a single word? I know of Text().toUpperCase(), but I'd like to capitalize only the first letter, not the whole word. Will I need to use Regex, or does Flutter have a built-in function for that?
Asked
Active
Viewed 206 times
-2
-
2https://stackoverflow.com/questions/29628989/how-to-capitalize-the-first-letter-of-a-string-in-dart – Amit Prajapati Sep 18 '19 at 08:43
-
productName.text.toString()[0].toUpperCase() + productName.text.substring(1).toLowerCase() – Hardik Kumbhani Sep 18 '19 at 09:06
-
it is [duplicate] https://stackoverflow.com/questions/29628989/how-to-capitalize-the-first-letter-of-a-string-in-dart – Mohammad Nazari Dec 22 '19 at 08:38
1 Answers
1
I hope this helps.
String foo = 'example';
String bar = '';
if (foo.length > 0) {
bar = foo[0].toUpperCase() + foo.substring(1);
}
print(bar); // Example

Durdu
- 4,649
- 2
- 27
- 47