-2

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?

Mr Jax
  • 957
  • 12
  • 22

1 Answers1

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