How to add red asterisk in label of TextFormField In Flutter

前端 未结 3 368
小鲜肉
小鲜肉 2021-01-19 11:49

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 i

3条回答
  •  暖寄归人
    2021-01-19 12:36

    Simplest way, but not exactly equals:

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

    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: [
                          TextSpan(
                            text: '*',
                            style: TextStyle(color: Colors.red),
                          ),
                        ],
                        style: TextStyle(color: Colors.black54),
                      ),
                    ),
                  ),
    

提交回复
热议问题