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

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

问题描述

由于我们无法制作像RichText/Text Span这样的小部件来为TextFormField设置样式, 我们如何获得这样的结果? 谁能帮我这个忙... 预先感谢.

As we are not able to make widget like RichText/Text Span For styling TextFormField, How we can achieve a result like this? Can anyone help me out regarding this... thanks in advance.

现在正在获取:-

预期结果:-

推荐答案

最简单的方法,但不完全相同:

Simplest way, but not exactly equals:

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

或创建一个自定义的TextField以将提示用作窗口小部件而不是字符串

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

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

You can use my two customized files:

  • input_decorator.dart
  • text_field_custom.dart
              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天全站免登陆