首页 > 解决方案 > 在文本表单字段的文本末尾添加不可编辑的字符串

问题描述

当用户在文本表单字段中输入值时,我试图在末尾添加字符串值。我可以添加值作为后缀,但我想将值添加到非常接近文本表单字段输入的位置。

TextFormField(
                                style: TextStyle(
                                                    color: Colors.black,
                                                    fontSize: 20),
                                                keyboardType:
                                                    TextInputType.number,
                                                controller:
                                                    loanTenureController,
                                                focusNode: loanTenureFocus,
                                                cursorColor: Colors.blueGrey,
                                                inputFormatters: [
                                                  WhitelistingTextInputFormatter(
                                                      RegExp("[0-9]")),
                                                  LengthLimitingTextInputFormatter(
                                                      2)
                                                ],
                                                decoration: InputDecoration(
                                                  border: InputBorder.none,
                                                  labelText: S
                                                      .of(context)
                                                      .loanTenureInYears,
                                                  labelStyle: TextStyle(
                                                    fontSize: 18,
                                                    color: getColor(
                                                        snapshot.data,
                                                        loanTenureFocus,
                                                        "loanTenure"),
                                                  ),
                                                ),
                                              ),
```[![enter image description here][1]][1]
i want like this field

[![在此处输入图像描述][1]][1]

标签: flutter

解决方案


然后将您的文本字段放在表单小部件中:

 Form(
    onChanged: () {
      _textEditingController.text = _textEditingController.text + 
      suffixThatYouWant.toString() 
    }
 ),

推荐阅读