如何从 TextField 中删除内容填充? [英] How do I remove content padding from TextField?
问题描述
我是 Flutter 的新手,我正在创建登录表单,因为我使用了 TextField 并添加了前缀图标,但我在文本字段(用户 ID 和 pin)之间和前缀图标之前得到了一些额外的空格.我也尝试过 InputDecorationTheme 但它没有用.
I am new to flutter and I am creating login form, for that I have used TextField and added prefix icon but I am getting some extra spaces in between textfields (user id and pin) and before the prefix icon. I have also tried InputDecorationTheme but it didn't work.
请告诉我如何删除或减少空间.??
Please let me know how can I remove or reduce the space.??
下面是我的代码:
TextField(
maxLength: 8,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: hint,
hintStyle: TextStyle(fontSize: 12.0),
prefixIcon: Icon(icon),
counterText: '',
),
)
推荐答案
更新(2021 年 4 月):仍然在 Flutter 2.0.4 中工作
Update (April 2021): still work in flutter 2.0.4
从 Flutter 1.17.5 开始(在 1.2X 中仍然如此)要完全手动删除或操作填充,首先您必须设置 isDense: true
然后您可以调整 contentPadding
你想要的,或者在父小部件上应用填充.
As of flutter 1.17.5 (and still the same in 1.2X) to completely remove or manipulate the padding manually, first you must set isDense: true
and then you can adjust the contentPadding
as you wanted or apply padding on the parent widget instead.
TextField(
inputDecorationTheme: InputDecorationTheme(
isDense: true,// this will remove the default content padding
// now you can customize it here or add padding widget
contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
...
),
)
这篇关于如何从 TextField 中删除内容填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!