【问题标题】:How to align suffixIcon to top of multi line TextField?如何将 suffixIcon 对齐到多行 TextField 的顶部?
【发布时间】:2020-12-11 11:17:11
【问题描述】:

代码:

TextField(
  maxLines:null,
  decoration: InputDecoration(
  suffixIcon: Icon(Icons.delete),
  ),
)

每次插入新行时,图标都会居中。

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    我找到了解决方法。只需使用TextFieldsuffix 属性而不是suffixIcon

    代码:

    TextField(
      maxLines:null,
      decoration: InputDecoration(
      suffix: Icon(Icons.delete),
      ),
    )
    

    输出:

    注意:此解决方案可能会影响您的TextField 的设计,并且当TextField 没有聚焦或没有数据时,Icon 不可见

    【讨论】:

      【解决方案2】:

      这是我在Icon 周围使用Padding 所取得的成果:

      Container(
          height: 100,
          child: TextField(
            expands: true,
            maxLines: null,
            decoration: InputDecoration(
                suffixIcon: Padding(
              padding:
                  const EdgeInsets.only(left: 0, top: 0, right: 0, bottom: 100),
              child: Icon(Icons.add),
            )),
          ),
        )
      

      【讨论】:

      • 此解决方案仅在 TextField 的高度固定时才有效。如果高度增加,对齐方式就会改变。我希望 TextFields 的高度是动态的并保持对齐。
      • 好吧我不知道,因为你没有在你的问题中提到这一点@FiroshVasudevan
      猜你喜欢
      • 2022-01-19
      • 2023-04-04
      • 1970-01-01
      • 2013-10-31
      • 2015-04-02
      • 2010-12-17
      • 2014-07-20
      • 2019-10-28
      • 1970-01-01
      相关资源
      最近更新 更多