dart - 输入文本时自动扩展的 Flutter 文本字段,然后在达到特定高度时开始滚动文本

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

我正在寻找一个最初是单行的文本字段,它会在输入文本时自动扩展,然后在某个时候开始自行滚动。

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

如果将 maxLines 设置为一个值,则整个文本字段本身会扩展为从多行开始,而不是从单行开始。

有没有办法像在 WhatsApp 和电报等许多聊天应用程序中那样在某些时候限制文本字段的高度。

最佳答案

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

在旧的 Flutter 版本中是

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

https://stackoverflow.com/questions/51205333/

相关文章:

flutter - 如何在不改变 AppBar 的情况下更改 TabBar 的背景颜色?

ios - flutter IOS : CocoaPods could not find compa

android - 如何在 Flutter 中创建可扩展的 ListView

dart - Flutter 测试 MissingPluginException

http - 在flutter http请求中为所有请求设置默认 header 的最佳方法

visual-studio-code - VS Code(OSX)Flutter热重载不是由保存触发

flutter - 为什么某些变量在 flutter 自定义类中标记为最终变量?

android - flutter 上的图像比例类型中心裁剪?

firebase - 从 Flutter 中的 Firestore 集合中获取所有内容

animation - 在 Flutter 中将 ListView 项目动画化为全屏