How to add red asterisk in label of TextFormField In Flutter

前端 未结 3 365
小鲜肉
小鲜肉 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:26

    Try these two files I had same requirement. Just add attribute isMandate: true in CInputDecoration and use CTextField.

    CTextField(
    ...
      decoration: new CInputDecoration(
         isMandate: true,
    ...
    ))
    

    https://github.com/sumit1954/Flutter/blob/master/CInputDecorator.dart https://github.com/sumit1954/Flutter/blob/master/CTextField.dart

    0 讨论(0)
  • 2021-01-19 12:30

    Achieved this in hard fast way. Replace input_decorator.dart with below code:

    https://github.com/neal786y/InputDecoratorForMandatoryFields/blob/master/input_decorator.dart

    In your InputDecoration scope add a property "isMandatoryField: true"

    Worked for me on temporary basis.

    0 讨论(0)
  • 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: <InlineSpan>[
                          TextSpan(
                            text: '*',
                            style: TextStyle(color: Colors.red),
                          ),
                        ],
                        style: TextStyle(color: Colors.black54),
                      ),
                    ),
                  ),
    
    0 讨论(0)
提交回复
热议问题