【问题标题】:Cannot remove underside padding from TextField and TextFormField in Flutter无法从 Flutter 中的 TextField 和 TextFormField 中删除底边填充
【发布时间】:2020-04-18 02:34:05
【问题描述】:

我有这个小部件:

TextFormField(
  controller: _activityName,
  autocorrect: true,
  textAlign: TextAlign.start,
  decoration: InputDecoration(
      contentPadding = EdgeInsets.zero,



      border: UnderlineInputBorder(

      ),

      hintText: ""),
  maxLines: 1,
  cursorColor: Colors.white,
),

如您所见,我明确地将填充设置为 0,正如这个答案所说: How do I remove content padding from TextField?

但是我得到的结果是这样的:

正如您在 Text MyActivity 下看到的,有很多填充,但我无法摆脱它。 它看起来像一个错误,但我不确定:

这是颤振医生:

Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18362.295], locale en-US)
    • Flutter version 1.12.13+hotfix.5 %Flutter path%
    • Framework revision 27321ebbad (3 weeks ago), 2019-12-10 18:15:01 -0800
    • Engine revision 2994f7e1e6
    • Dart version 2.7.0

【问题讨论】:

  • 据说填充是有意的。来源:flutter issue.
  • @Harshvardhan Joshi 所以我不能以任何方式删除它?
  • 我不这么认为。因为我已经尝试过 TextField 中所有可能的填充值都为零,并且它仍然具有相同的填充。
  • @HarshvardhanJoshi 好的,感谢您抽出宝贵时间帮助我!让我们希望尽快修复!
  • 如果你看到了这个问题,他们说这是故意的。所以也许我们可以要求一个可选的“补偿”参数来删除额外的填充。

标签: flutter dart


【解决方案1】:

来自https://stackoverflow.com/a/59295394/4465386 - 也可以查看演示。

这是获取 0 填充文本字段的方法:

TextField(
  decoration: InputDecoration(
    contentPadding: EdgeInsets.all(0),
    isDense: true,
  ),
);

【讨论】:

    【解决方案2】:

    您可以使用折叠来删除一点空间:

    TextField(
      decoration: InputDecoration.collapsed(hintText: null),
    ),
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      相关资源
      最近更新 更多