Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextAllCaps in Text() widget of Flutter?

Tags:

As we are having android:textAllCaps="true" feature in Android's Textview, how can we give this same feature in Text() Widget of Flutter?

I know Text('Abc'.toUpperCase()), is one way but I don't want to do it manually. Is there any property of Text() widget that converts it automatically or any widget that has similar property?

like image 355
Gaurang Goda Avatar asked Apr 12 '19 14:04

Gaurang Goda


People also ask

How do I make text all caps in Flutter?

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.


2 Answers

(EDITED) My solution is like this:

Text("apple".toUpperCase()) 
Returns:  APPLE 
like image 198
Guvanch Avatar answered Oct 31 '22 07:10

Guvanch


Use following function for the First word as Caps

String getCapitalizeString({String str}) {     if (str.length <= 1) { return str.toUpperCase(); }     return '${str[0].toUpperCase()}${str.substring(1)}'; } 

Use :

Text(this.getCapitalizeString(str: listObj[position]); 
like image 20
Dharmesh Mansata Avatar answered Oct 31 '22 08:10

Dharmesh Mansata