flutter - 无法在 Flutter TextField 小部件中垂直居中输入文本和后缀
问题描述
我很难在 TextField Flutter 小部件中对齐输入分机和后缀。我尝试将它们垂直居中,但由于某种原因不能这样做。
当我不指定后缀时,输入文本根据需要垂直居中: 当我指定后缀时,输入文本下降而后缀上升,因此它们都不是垂直居中的:
我的代码:
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
title: Text('test'),
),
body: Container(
color: Colors.grey.shade800,
margin: EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
height: 70,
alignment: Alignment.centerLeft,
child: TextField(
style: TextStyle(
textBaseline: TextBaseline.alphabetic,
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w400,
decoration: TextDecoration.none,
),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
suffix: Icon(
Icons.clear,
color: Colors.red,
),
suffixStyle: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
fontWeight: FontWeight.w400,
fontSize: 17,
textBaseline: TextBaseline.ideographic,
),
border: InputBorder.none,
hintText: "Search",
),
),
),
);
问题:
我应该怎么做才能垂直居中输入文本和后缀?
解决方案
包裹图标Transform.translate
并为其设置propper偏移
推荐阅读
- ssl - 支付网关 HTTP 错误:cURL 错误:51:SSL:证书主题名称“seguro3.cpmp.com.gt”与目标主机名“190.0.195.24”不匹配
- error-correction - 里德所罗门纠错和误报
- python - Flask 没有记录 HTTP 请求
- jquery - jQuery UI“CHOSEN”插件:选择列表上的删除选项不起作用
- javascript - 我可以发现在表单字段中输入的值吗?
- c - 生成文件不起作用?'makefile' 无事可做
- python-3.x - 在 python 中传递 DOS/Windows 路径
- excel - 如何使用 VB 宏在 Excel 中拆分自定义日期时间格式?
- python - 如何在一个绘图图形上绘制两个 Pandas 系列?
- excel - 从范围的 foreach 传递行,ByRef 参数类型不匹配