如何使 TextField hintText 垂直居中?
how to make TextField hintText vertical center?
我试了很多方法
文本对齐:TextAlign.Center
contentPadding: const EdgeInsets.all(20.0)
但它们没用。
enter image description here
Expanded(
child: Container(
height: 30.0,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(18),
),
margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 10.0),
child: const TextField(
style: TextStyle(fontSize: 14.0),
decoration: InputDecoration(
border: InputBorder.none,
hintText: '请输入搜索词',
hintStyle: TextStyle(fontSize: 13.0),
prefixIcon: Icon(
Icons.search,
size: 18.0,
color: Colors.grey,
),
suffixIcon: Icon(
Icons.clear,
size: 18.0,
color: Colors.grey,
),
),
),
),
),
试试下面的代码,使用 textAlign: TextAlign.center,
TextField(
textAlign: TextAlign.center,
style: TextStyle(fontSize: 14.0),
decoration: InputDecoration(
border: InputBorder.none,
hintText: '请输入搜索词',
hintStyle: TextStyle(fontSize: 13.0),
prefixIcon: Icon(
Icons.search,
size: 18.0,
color: Colors.grey,
),
suffixIcon: Icon(
Icons.clear,
size: 18.0,
color: Colors.grey,
),
),
),
结果屏幕->
我试了很多方法
文本对齐:TextAlign.Center
contentPadding: const EdgeInsets.all(20.0)
但它们没用。
enter image description here
Expanded(
child: Container(
height: 30.0,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(18),
),
margin: const EdgeInsets.symmetric(vertical: 0, horizontal: 10.0),
child: const TextField(
style: TextStyle(fontSize: 14.0),
decoration: InputDecoration(
border: InputBorder.none,
hintText: '请输入搜索词',
hintStyle: TextStyle(fontSize: 13.0),
prefixIcon: Icon(
Icons.search,
size: 18.0,
color: Colors.grey,
),
suffixIcon: Icon(
Icons.clear,
size: 18.0,
color: Colors.grey,
),
),
),
),
),
试试下面的代码,使用 textAlign: TextAlign.center,
TextField(
textAlign: TextAlign.center,
style: TextStyle(fontSize: 14.0),
decoration: InputDecoration(
border: InputBorder.none,
hintText: '请输入搜索词',
hintStyle: TextStyle(fontSize: 13.0),
prefixIcon: Icon(
Icons.search,
size: 18.0,
color: Colors.grey,
),
suffixIcon: Icon(
Icons.clear,
size: 18.0,
color: Colors.grey,
),
),
),
结果屏幕->