【问题标题】:how to add Asterisks symbol in red color to the textformfiled in flutter如何在颤动中将红色星号符号添加到文本表单字段
【发布时间】:2021-05-10 13:04:45
【问题描述】:

[1]我是flutter的新手,如何在flutter中的textformfiled中添加红色星号符号和黑色提示,请帮助我

[在此处输入图像描述] [1]:https://i.stack.imgur.com/bwli2.png

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    我不确定您希望星号在哪里,但在TextFormField 中,您可以使用decoration 参数传递InputDecoration

    这使您可以像这样传递labelTextlabelStyle 以及hintTexthintStyle

    class FormFieldWithAsterisk extends StatelessWidget {
      const FormFieldWithAsterisk({Key key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return TextFormField(
          decoration: InputDecoration(
              labelText: "*",
              labelStyle: TextStyle(color: Colors.red),
              hintText: "type here...",
              hintStyle: TextStyle(color: Colors.black)),
        );
      }
    }
    

    结果如下:

    【讨论】:

    • 谢谢,我需要黑色的提示文本颜色和红色的星号符号。
    • 提示的工作方式相同,例如使用hintTexthintStyle
    • 当我使用提示样式时,它也适用于文本和符号。我需要不同颜色的提示文本和星号 synbol。
    • 感谢您的回答,实际上,我需要在提示文本旁边使用星号。
    • 啊,您可以使用 RichText 小部件以不同的方式设置文本部分的样式。但是在TextFormField 中,您不能将小部件作为提示传递,只能传递文本。我认为材料设计指南禁止您使用不同的颜色作为提示。所以我建议要么扩展FormField<String> 并自己实现FormField,要么尝试使用prefixIcon 字段,您可以在其中传递任何小部件。
    猜你喜欢
    • 2011-06-03
    • 2019-07-03
    • 2018-04-04
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 2019-06-19
    相关资源
    最近更新 更多