[英]How to add search icon to TextField in Flutter?
是否可以在TextField
中显示提示,如下图所示?
没有在提示中添加图标的正确方法,但是您可以尝试这种替代方法,在文本字段上使用富文本作为提示文本,在点击文本字段时隐藏并在文本字段为空且键盘隐藏时显示条件:
Stack(
alignment: AlignmentDirectional.center,
children: [
Offstage(
offstage: _isHide,
child: IgnorePointer(
ignoring: true,
child: Text.rich(
TextSpan(
children: [
WidgetSpan(
child: Icon(
Icons.search,
color: Colors.grey,
),
),
TextSpan(
text: "blablablablabla",
style: TextStyle(color: Colors.grey),
),
],
),
),
),
),
TextField(onTap: () {
_isHide = true;
setState(() {});
}),
],
),
在文本字段小部件中使用Prefix icon
属性和内容填充
SizedBox(
height: 40.h,
child: TextField(
decoration: InputDecoration(
fillColor: ColorUtils.COLOR_GRAY_AAAAAA[12],
filled: true,
contentPadding: EdgeInsets.symmetric(vertical: 6.h, horizontal: 12.w),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.r)),
borderSide: BorderSide.none,
),
hintText: 'input_order_code'.tr,
hintStyle: TextStyleUtils.sizeText15Weight400().copyWith(color: ColorUtils.COLOR_GRAY_AAAAAA),
prefixIcon: Icon(Icons.search),
),
style: TextStyleUtils.sizeText15Weight400().copyWith(color: ColorUtils.COLOR_GRAY_363636),
),
),
SizedBox(
height: 50,
child: TextField(
cursorHeight: 25,
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
hintText: 'Search Here...'),
),
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.