如何只对Flutter中TextField中的文本应用填充? [英] How do I only apply padding to the text in a TextField in Flutter?

查看:372
本文介绍了如何只对Flutter中TextField中的文本应用填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有填充,我得到以下结果:

Without padding I get this result:

Padding(padding: EdgeInsets.all(20.0), child: TextField())

我得到以下结果:

这可能很难看,但是您只需要查看边缘的红色徽章即可理解我的意思。

It might be a bit hard to see, but you only have to look at the red badge across the edge to realise what I mean.

我只想使用填充来移动文本,但实际上,整个 TextField 都应用了填充,即下划线随填充一起移动,但我想让下划线仍遍及整个视图,只有 TextField 内的文本受填充影响。

I would like to only move the text with my padding, but in reality the whole TextField has the padding applied, i.e. that the underline moves with the padding, but I would like to have the underline still go across the whole view, that only the text inside the TextField is affected by the padding.

推荐答案

将填充应用于TextField的内容。您可以将ItemDecoration的

To apply the padding to the content of the TextField. You can apply the


contentPadding属性应用于TextField的装饰属性。

contentPadding property of ItemDecoration at decoration property of TextField.

像这样:

new TextField(
          textAlign: TextAlign.left,
          decoration: new InputDecoration(hintText: "Enter Something", contentPadding: const EdgeInsets.all(20.0))
          )

这篇关于如何只对Flutter中TextField中的文本应用填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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