在文本表单字段的文本末尾添加不可编辑的字符串

时间:2019-04-26 10:26:15

标签: flutter

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

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]

1 个答案:

答案 0 :(得分:0)

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

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