我是 Flutter 的新手,我正在创建登录表单,因为我使用了 TextField 并添加了前缀图标,但我在文本字段(用户 ID 和 pin)之间和前缀图标之前得到了一些额外的空格。我也尝试过 InputDecorationTheme 但它没有用。
请告诉我如何删除或减少空间。??
下面是我的代码:
TextField(
maxLength: 8,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: hint,
hintStyle: TextStyle(fontSize: 12.0),
prefixIcon: Icon(icon),
counterText: '',
),
)
最佳答案
更新(2022 年 8 月):仍与 Flutter 3.0.5 相同
更新(2021 年 4 月):仍在 Flutter 2.0.4 中工作
从 Flutter 1.17.5 开始(在 2.X 中仍然相同)要完全手动删除或操作填充,首先您必须设置 isDense: true
然后您可以调整 contentPadding
你想要的,或者在父小部件上应用填充。
// using theme
ThemeData(
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),
...
),
)
// per widget
TextField(
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
...
),
)
正如 Ataberk 的评论中所述你也可以使用 contentPadding: EdgeInsets.zero
TextField(
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.zero,
...
),
)
https://stackoverflow.com/questions/53644897/