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

9
标题已经很好地概括了问题。我有一个TextField,其maxLength:250,它看起来像这样:

enter image description here

有没有办法将计数器放在其他地方?最好是在发送按钮的左侧,否则可能只能放在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)),
2个回答

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())),
  ),
)

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

在TextField中使用修饰语。添加counterText:' '。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接