Flutter的Text()小部件中的TextAllCaps? [英] TextAllCaps in Text() widget of Flutter?

查看:36
本文介绍了Flutter的Text()小部件中的TextAllCaps?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在Android的Textview中具有 android:textAllCaps ="true" 功能时,如何在 Text() 中提供相同的功能> Flutter的小工具?

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

我知道 Text('Abc'.toUpperCase())是一种方法,但我不想手动进行.是否有Text()小部件的任何属性可以自动将其转换,或者任何具有类似属性的小部件?

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?

推荐答案

使用以下函数将第一个单词用作大写字母

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)}';
}

使用:

Text(this.getCapitalizeString(str: listObj[position]);

这篇关于Flutter的Text()小部件中的TextAllCaps?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆