【问题标题】:How to add icon inside textfield如何在文本字段中添加图标
【发布时间】:2019-02-13 20:12:00
【问题描述】:

我已使用 icon: Icon(Icons.mail), 将图标添加到文本字段,但它出现在文本字段之外。

如何改变图标的​​位置,使其显示在文本框内。

文本字段:

TextField(
  decoration: InputDecoration(
    icon: Icon(Icons.mail),
  ),
),

【问题讨论】:

    标签: flutter textfield


    【解决方案1】:

    你需要使用prefixIcon属性而不是iconlike

    TextField(
      decoration: InputDecoration(prefixIcon: Icon(Icons.mail)),
    )
    

    【讨论】:

      【解决方案2】:

      前缀图标:

      出现在 prefixText 和 文本字段的可编辑部分,位于装饰容器内。

      以下代码适用于问题

      TextField(
        decoration: InputDecoration(
          prefixIcon: Icon(Icons.mail),
        ),
      );
      

      如果我们想用一些填充来排列图标,我们可以这样做:

       prefixIcon: Padding(
                padding: const EdgeInsetsDirectional.only(start: 30.0),
                child: Icon(Icons.access_alarm), // Change this icon as per your requirement
              )
      

      【讨论】:

      • 如果您希望它位于文本字段的末尾而不是文本之前怎么办?能做到吗?
      猜你喜欢
      • 2019-11-01
      • 2018-04-08
      • 1970-01-01
      • 2020-01-13
      • 2017-02-22
      • 1970-01-01
      • 1970-01-01
      • 2015-12-21
      • 1970-01-01
      相关资源
      最近更新 更多