【问题标题】:Flutter: How to move TextField characer counter?Flutter:如何移动文本字段字符计数器?
【发布时间】:2019-09-19 21:35:11
【问题描述】:

标题很好地总结了这个问题。我有一个TextField 和一个maxLength: 250,这就是它的样子:

有没有办法把柜台放在别的地方?最好在发送按钮的左侧,否则可能就在TextField 的上方和左侧。有任何想法吗?谢谢!

可能没有必要,但这是我的代码:

TextField(
              controller: inputTextEditingController,
              focusNode: inputFocusNode,
              style: TextStyle(color: Platform.isAndroid ? Colors.green : Colors.blue, height: 0.8),
              maxLength: 250,
              maxLines: null,
              decoration: InputDecoration(
                  contentPadding: const EdgeInsets.fromLTRB(20, 15, 0, 15),
                  border: OutlineInputBorder(
                      borderRadius: BorderRadius.circular(28)),
                  focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Platform.isAndroid ? Colors.green : Colors.blue),
                      borderRadius: BorderRadius.circular(28)),
                  suffixIcon: IconButton(
                    onPressed: _handleSubmitted,
                    icon: Padding(
                      padding: const EdgeInsets.fromLTRB(0, 0, 20, 0),
                      child: Icon(Icons.send,
                          color: inputFocusNode.hasFocus
                              ? Platform.isAndroid ? Colors.green : Colors.blue
                              : Colors.black54),
                    ),
                  ),
                  hintText: "Say something!",
                  hintStyle: inputFocusNode.hasFocus
                      ? TextStyle(color: Platform.isAndroid ? Colors.green : Colors.blue, fontSize: 16)
                      : TextStyle(color: Colors.black54)),

【问题讨论】:

    标签: user-interface flutter dart textfield maxlength


    【解决方案1】:

    您需要构建自己的计数器并将其作为 TextField Widget 的 buildCounter 参数传递。

    TextField(
      maxLength: 250,
      buildCounter: (_, {currentLength, maxLength, isFocused}) => Padding(
        padding: const EdgeInsets.only(left: 16.0),
        child: Container(
            alignment: Alignment.centerLeft,
            child: Text(currentLength.toString() + "/" + maxLength.toString())),
      ),
    )
    

    【讨论】:

      【解决方案2】:
        child: new TextField(
                        style: BurmeseUtil.textStyle(context),
                        controller: txtController,
                        maxLength: 1500,
                        maxLines: null,
                        decoration: new InputDecoration(
                          counterText: '',
                          border: OutlineInputBorder(),
                        ),
                      ),
      

      在 TextField 中使用装饰。添加 counterText:' ' 祝你好运

      【讨论】:

        猜你喜欢
        • 2020-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-14
        • 1970-01-01
        • 2021-07-06
        相关资源
        最近更新 更多