当输入文本时自动展开的Flutter文本字段,当达到一定高度时开始滚动文本 [英] Flutter textfield that auto expands when text is entered and then starts scrolling the text when a certain height is reached

查看:449
本文介绍了当输入文本时自动展开的Flutter文本字段,当达到一定高度时开始滚动文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了Flutter TextField的许多配置,但不知道如何构建它。

I've tried many configurations of the Flutter TextField but can't figure out how to build this one.

我正在寻找一个文本框,它是一个

I'm looking for a textfield that is a single line initially and it auto expands as the text is entered into it and then at some point begins scrolling itself.

这可以通过使用maxLines:null属性部分实现,并在输入文本时自动扩展。 。但是,当输入大量文本时,文本字段中的文本本身就会溢出。

This can be achieved partially by using the maxLines: null attribute. But then when a lot of text is entered the Text in the textfield itself overflows.

如果将maxLines设置为一个值,则整个文本字段本身都会扩展为那些

And if the maxLines is set to a value then the whole textfield itself gets expanded to those many lines to start off with rather than beginning with a single line.

是否有一种方法可以限制文本字段的高度,就像在某些聊天应用程序(如WhatsApp)中所做的那样

Is there a way to limit the height of textfield at some point like done in many chat apps like WhatsApp and telegram.

推荐答案

Container(
    child: new ConstrainedBox(
        constraints: BoxConstraints(
            maxHeight: 300.0,
        ),
        child: TextField(
                    maxLines: null,
                ),
            ),
        ),
    ),
)

在较旧的Flutter中

In older Flutter versions it was

Container(
    child: new ConstrainedBox(
        constraints: BoxConstraints(
            maxHeight: 300.0,
        ),
        child: new Scrollbar(
            child: new SingleChildScrollView(
                scrollDirection: Axis.vertical,
                reverse: true,
                child: new TextField(
                    maxLines: null,
                ),
            ),
        ),
    ),
)

这篇关于当输入文本时自动展开的Flutter文本字段,当达到一定高度时开始滚动文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆