Flutter,TextFormField 的内容填充未按预期工作

Lar*_*335 4 android flutter flutter-layout

Flutter 应用程序,android:我正在尝试减少 TextFormField 的底部填充(我需要将相当多的字段安装到相当小的屏幕上 [移动 android 数据收集器])。

我尝试过使用 contentPadding InputDecoration,但它没有像我预期的那样工作。

这是底部填充为 10 的情况:

decoration: InputDecoration(
...
  contentPadding: new EdgeInsets.fromLTRB(10, 10, 10, 10):
Run Code Online (Sandbox Code Playgroud)

底部填充为 10

这是底部填充为 4 的情况:

decoration: InputDecoration(
...
  contentPadding: new EdgeInsets.fromLTRB(10, 10, 10, 4):
Run Code Online (Sandbox Code Playgroud)

底部填充为 4

正如您所看到的,TextFormFields 内文本的底部填充没有太大变化,仍然有太多浪费的空间;此外,由于某种原因,顶部填充也发生了变化,使得内容文本与标签文本太接近。我不想改变顶部填充。

如何减少底部填充(文本和边框之间)?

编辑 2019 年 11 月 18 日,每个请求的完整 TextFormField:

TextFormField(
  initialValue: widget.initialValue,
  textInputAction: TextInputAction.next,
  enabled: widget.enabled,
  minLines: widget.lines,
  maxLines: widget.lines,
  autofocus: widget.autoFocus,
  focusNode: widget.focusNode,
  keyboardType: widget.keyboardType,
  maxLength: widget.maxLength,
  maxLengthEnforced: true,
  readOnly: widget.readonly,
  inputFormatters: widget.inputFormatters,
  controller: widget.controller,
  style: TextStyle(
    fontSize: 17,
    color: widget.textColor != null ? widget.textColor : null,
  ),
  onFieldSubmitted: widget.onFieldSubmitted,
  onEditingComplete: widget.onEditingComplete,
  decoration: InputDecoration(
    labelText: widget.labelText,
    labelStyle: TextStyle(color: widget.enabled ? Colors.grey[600] : Colors.grey[500]),
    hintText: widget.hintText != null ? widget.hintText : widget.labelText,
    counterText: '',
    errorText: widget.errorText,
    filled: true,
    fillColor: widget.fillColor != null ? widget.fillColor : widget.enabled ? Colors.white : Colors.grey[100],
    contentPadding: new EdgeInsets.fromLTRB(10, 10, 10, 10),
    border: OutlineInputBorder(),
  ),
),
Run Code Online (Sandbox Code Playgroud)

kei*_*ira 8

尝试在 inputDecoration 中添加isDense:true来填充小于默认值的填充。这对我有帮助


decoration: InputDecoration(
         isDense: true,


        // contentPadding: new EdgeInsets.fromLTRB(0, 0, 0, 0),

         contentPadding: EdgeInsets.only(top: 4,bottom: 4,left: 6,right: 6),
         hintText: "Enter name",

         hintStyle: TextStyle(color: Colors.grey),
         border: InputBorder.none,
       ),
Run Code Online (Sandbox Code Playgroud)