在Flutter中如何在文本字段的标签中添加红色星号(*)

huangapple go评论47阅读模式
英文:

How to add red asterisk(*) in label of text field In Flutter

问题

在Flutter中如何在文本字段的标签中添加一个红色星号。
[请在这里查看我想要的效果][1]。我尝试过了,但是出现了错误。

[1]: https://i.stack.imgur.com/Inm31.jpg

    Container(
                  width: 310,
                  child: CTextField(
                    decoration: new CInputDecoration(
                      isMandate: true,
                      labelText: '名字',
                      labelStyle: GoogleFonts.lato(
                          color: Color(0xffb0b0b0),
                          fontSize: 19,
                          letterSpacing: 0.5),
                      
                    ),
                  ),
                ),
英文:

How to add a red asterisk in the label of the text field In Flutter.
Please see here to find what I want. I tried, but I am getting error.

Container(
              width: 310,
              child: CTextField(
                decoration: new CInputDecoration(
                  isMandate: true,
                  labelText: 'First Name',
                  labelStyle: GoogleFonts.lato(
                      color: Color(0xffb0b0b0),
                      fontSize: 19,
                      letterSpacing: 0.5),
                  
                ),
              ),
            ),

答案1

得分: 0

你可以尝试以下的代码:

SizedBox(
  width: 310,
  child: TextField(
    decoration: InputDecoration(
      label: RichText(
        text: TextSpan(
          text: 'Full Name',
          style: const TextStyle(
            color: Colors.grey),
            children: [
               TextSpan(
                  text: ' *',
                  style: TextStyle(
                    color: Colors.red,
                  )
               )
            ]
          ),
        ),
      ),
    floatingLabelBehavior:FloatingLabelBehavior.never, 
  ),
)
英文:

You can try this code:

SizedBox(
  width: 310,
  child: TextField(
    decoration: InputDecoration(
    label: RichText(
       text: TextSpan(
            text: 'Full Name',
            style: const TextStyle(
              color: Colors.grey),
              children: [
                 TextSpan(
                    text: ' *',
                    style: TextStyle(
                      color: Colors.red,
                    )
                 )
              ]
            ),
          ),
          floatingLabelBehavior:FloatingLabelBehavior.never, 
        ),
      ),
)

huangapple
  • 本文由 发表于 2023年2月16日 19:21:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471534.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定