Container(
height: w(54),
alignment: Alignment.centerLeft,
margin: EdgeInsets.fromLTRB(w(24), w(9), w(9), w(12)),
padding: EdgeInsets.only(left: 6, right: 6),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(4)),
color: Color(0xFFF2F5FA)),
child: TextField(
onTap: () {
setState(() {
mode = MODE_KEYBOARD;
showFlag = true;
});
},
style: TextStyle(fontSize: sp(21), color: Color(0xD6000000)),
controller: controller,
autofocus: false,
decoration: InputDecoration(
isDense: true,
border: InputBorder.none,
contentPadding: EdgeInsets.zero),
),
),
当Container设置高度以后,发现输入的文字一直在Container底部显示,这个时候设置这三个关键属性:
alignment: Alignment.centerLeft,
contentPadding: EdgeInsets.zero,
isDense : true(用于编辑框对齐),
可以实现输入的文字Container中居中显示!