繁体   English   中英

当用户输入时,如何使 TextField 扩展?

[英]How to make the TextField expands in flutterwhen the user types in it?

我正在设置一个文本字段,当我尝试在最大行中设置 null 时,在键盘上按下 Enter 时该文本字段将扩展它不显示文本字段内的文本我什至设置为展开 = true 我在某处使用了媒体查询大小代码中的 size.height 我将文本字段包装在灵活小部件中并添加一些填充,然后整个灵活小部件被包装在一个行中,最后该行被包装在一个容器中

所以这段代码不起作用帮助我解决这个问题

容器(

          height: size.height * .059,
          width: double.infinity,
          child: new Row(
            children: <Widget>[
              new Flexible(
                child: Padding(
                  padding: EdgeInsets.only(right: size.width * 0.007),
                  child: new TextField(
                    controller: _textFieldController,
                    textInputAction: TextInputAction.newline,
                    keyboardType: TextInputType.multiline,
                    maxLines: null,
                    expands: true,
                    style: TextStyle(color: Colors.black),
                    cursorColor: Colors.blue,
                    decoration: InputDecoration(
                      focusedBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(30.0),
                          borderSide: BorderSide(color: Color(0xff8e9291))),
                      enabledBorder: OutlineInputBorder(
                          borderRadius: BorderRadius.circular(30.0),
                          borderSide: BorderSide(color: Color(0xff8e9291))),
                      prefixIcon: Icon(
                        Icons.message,
                        color: Color(0xff8e9291),
                      ),
                      hintText: "Type a message",
                      hintStyle: TextStyle(
                        color: Color(0xff8e9291),
                      ),
                    ),
                  ),
                ),
              ),
              FloatingActionButton(
                backgroundColor: Colors.blue[400],
                onPressed: () {
                },
                tooltip: 'Send',
                child: RotationTransition(
                    turns: AlwaysStoppedAnimation(-35 / 360),
                    child: Icon(
                      Icons.send,
                      size: 20,
                    )),
              ),
            ],
          ),
        ),

这是我正在使用的文本字段..

您可以删除Container的高度,因为这将形成一个固定的高度,并删除TextFieldexpands ,因为这是为了使其填充其父高度。

您可以将 MaxLine 属性设置为 null 'maxLines: null` 这将使 textField 能够垂直展开

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM