Flutter TextField宽度应与所包含文本的宽度匹配 [英] Flutter TextField width should match width of contained text

查看:1516
本文介绍了Flutter TextField宽度应与所包含文本的宽度匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在颤动中,TextField没有固有宽度;它只知道如何将自身调整为其父容器的整个宽度.如何将宽度设置为所包含文本的宽度.

In flutter, TextField doesn't have an intrinsic width; it only knows how to size itself to the full width of its parent container. How do I set the width to the width of the contained text.

我尝试将TextField放在容器中

I tried putting the TextField inside a container

如此处概述 如何更新Flutter TextField的高度和宽度?

new Container(              
  width: 100.0,
  child: new TextField()
)

我希望TextField的宽度与它包含的文本的宽度匹配.输入文本时,TextField应该变宽,而删除文本时,TextField应该变窄.

I expect the width of the TextField to match the width of the text it contains. The TextField should grow wider as text is typed, and shrink narrower as text is deleted.

推荐答案

Flutter具有 IntrinsicWidth 为您进行计算.只需将TextFieldTextFormField包裹在其中,如下所示:

Flutter has IntrinsicWidth to do the calculation for you. Just wrap your TextField or TextFormField in it as follow:

IntrinsicWidth(child: TextField())

这篇关于Flutter TextField宽度应与所包含文本的宽度匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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