flutter - 如何在文本字段中添加图标

标签 flutter textfield

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

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

文本字段:

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

最佳答案

你需要使用 prefixIcon 属性而不是 icon 之类的

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

关于flutter - 如何在文本字段中添加图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54678674/

相关文章:

android - 在Android Studio中的Flutter上运行模拟器时出错

android - flutter 错误 "Android dependency ' androidx.core :core' has different version"using flutter_local_notifications and location packages

cocoa - 更新的 NSTableCellView.textField 未在表格显示中更新。

java - java中如何动态设置一个对象?

flutter - 在flutter升级v3.13后错误运行当前项目

flutter - 将flutter升级到1.22.0后auto_route包的问题

android - 库 com.google.android.gms :play-services-basement is being requested by various other libraries at [[15. 0.1,15.0.1]],但解析为 11.8.0

ios - Swift 以编程方式设置文本字段的占位符

swift - 用选定的 TableViewCell 填充文本字段?

javascript - 选择单选按钮时填充文本字段