//Convert to uppercase Text( "Hello World".toUpperCase(), ), //Convert to lowercase Text( "Hello World".toLowerCase(), ),
There are times that we need to convert the text of the Text widget to uppercase or lowercase. Sometimes it may be needed for English texts which must have all words capitalized. Another case is for displaying texts of different languages (in some languages all words must be written in uppercase). Whatever reasons you want to convert the text in Flutter, it can be done. Today we will show a few ways how Flutter developers can convert the text without changing style.
As we all know, Flutter is a framework created using the dart programming language. Dart has a method toUpperCase() that is used to capitalize the String text. The basic syntax for that is as below.
"My text is here".toUpperCase()
So we can also use this in our Flutter Text() widget to transform the text to uppercase letters.
Container( child: Text( 'Devsheet'.toUpperCase(), ), ),
Same as String.toUpperCase() method, toLowerCase() method is used in dart to convert string characters to lowercase. The basic syntax used is:
In the Flutter Text widget, we can use it like below.
Container( child: Text( 'Devsheet'.toLowerCase(), ), ),