微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我在 Flutter 中将文本字段设置为下一行时,文本会向上

如何解决当我在 Flutter 中将文本字段设置为下一行时,文本会向上

当我在文本字段中按 Enter 键时,我想去掉上面的字母。我该怎么办?

这是代码的一部分。

Container(
                          child: TextField(
                            textAlign: TextAlign.center,autofocus: true,// controller: myController,onChanged: (value) {
                              // print('$value');
                              setState(() {
                                mainText = value;
                              });
                            },keyboardType: TextInputType.multiline,minLines: 1,maxLines: 10,decoration: Inputdecoration(
                              focusedBorder: InputBorder.none,enabledBorder: InputBorder.none,hintText: "짧은 글귀를 집필해주세요",hintStyle:
                                  TextStyle(fontSize: 14,color: Colors.black),),)

解决方法

根据您的提示文本,您只需要短文本,并且可以通过仅与单行文本字段集成来实现

  Container(
      child: TextField(
        textAlign: TextAlign.center,autofocus: true,// controller: myController,onChanged: (value) {
          setState(() {
            mainText = value;
          });
        },keyboardType: TextInputType.text,// this is change
        textInputAction: TextInputAction.done,// this is change
        decoration: InputDecoration(
          focusedBorder: InputBorder.none,enabledBorder: InputBorder.none,hintText: "짧은 글귀를 집필해주세요",hintStyle: TextStyle(fontSize: 14,color: Colors.black),),)

对于多行文本:

keyboardType: TextInputType.multiline,maxLines: 5,textInputAction: TextInputAction.newline,

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。