【问题标题】:Add a uneditable string at the end of the text in text form field在文本表单字段的文本末尾添加不可编辑的字符串
【发布时间】:2019-04-26 19:21:29
【问题描述】:

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

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


    【解决方案1】:

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

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

    【讨论】:

    • idk 关于不可编辑的部分,但是如果文本包含确切的后缀,您可以在 onChanged 方法中控制文本,如果它没有再次复制后缀,则继续
    猜你喜欢
    • 1970-01-01
    • 2022-07-28
    • 2020-05-09
    • 2022-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 2017-04-10
    • 2017-10-13
    相关资源
    最近更新 更多