如何在 Flutter 中 TextFormField 的标签中添加红色星号 [英] How to add red asterisk in label of TextFormField In Flutter

查看:70
本文介绍了如何在 Flutter 中 TextFormField 的标签中添加红色星号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我们无法制作像 RichText/Text Span 这样的小部件来为 TextFormField 设置样式,

As we are not able to make widget like RichText/Text Span For styling TextFormField,

谁能帮我解决这个问题...

Can anyone help me out regarding this...

现在得到:-

预期结果:-

我们如何才能达到这样的结果?

How we can achieve a result like this?

推荐答案

最简单的方法,但不完全等于:

Simplest way, but not exactly equals:

              TextField(
                decoration: InputDecoration(
                  hintText: 'Ciao',
                  suffixText: '*',
                  suffixStyle: TextStyle(
                    color: Colors.red,
                  ),
                ),
              ),

或者创建一个自定义的TextField来使用hint作为Widget而不是String

Or create a custom TextField to use hint as Widget instead of String

您可以使用我的两个自定义文件:

You can use my two customized files:

              TextFieldCustom(
                hintText: Text.rich(
                  TextSpan(
                    text: 'FIRST NAME',
                    children: <InlineSpan>[
                      TextSpan(
                        text: '*',
                        style: TextStyle(color: Colors.red),
                      ),
                    ],
                    style: TextStyle(color: Colors.black54),
                  ),
                ),
              ),

这篇关于如何在 Flutter 中 TextFormField 的标签中添加红色星号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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