Flutter:如何移动 TextField 字符计数器?

Ril*_*ick 9 user-interface maxlength textfield dart flutter

标题很好地总结了这个问题。我有一个TextField带有 a 的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)),
Run Code Online (Sandbox Code Playgroud)

小智 18

您需要构建自己的计数器并将其作为 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())),
  ),
)
Run Code Online (Sandbox Code Playgroud)


H Z*_*Zan 3

  child: new TextField(
                  style: BurmeseUtil.textStyle(context),
                  controller: txtController,
                  maxLength: 1500,
                  maxLines: null,
                  decoration: new InputDecoration(
                    counterText: '',
                    border: OutlineInputBorder(),
                  ),
                ),
Run Code Online (Sandbox Code Playgroud)

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