[英]Flutter, how can I center a widget in a row, but not the other?
对于这个屏幕:
我想让黑色的日期像橙色的代码一样居中,刷新按钮跟在日期后面,可能会偏右一点。 其次,如何减少橙色代码和日期之间以及日期和搜索项之间的空间高度。
这是我的代码的一部分:
Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(0, 30, 0, 0),
child: Text(
adminPassword(_today),
style: TextStyle(
fontSize: 40,
fontWeight: FontWeight.bold,
color: Colors.orange[800]),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
Center(
child: Text(DateFormat('d/M/y').format(_today).toString()),
),
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {
setState(() {
_today = DateTime.now();
});
},
),
],
),
Padding(
padding: const EdgeInsets.fromLTRB(12, 10, 12, 20),
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(), labelText: 'Search Item'),
controller: _searchItemController,
),
),
Container(
height: 45,
width: 250,
decoration: BoxDecoration(
color: Colors.teal, borderRadius: BorderRadius.circular(16)),
child: TextButton(
onPressed: () {}
child: Text(
'Search',
style: TextStyle(color: Colors.white, fontSize: 20),
),
),
),
您可以放置另一个不透明度为0
的IconButton
来获得:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Opacity(
opacity: 0,
child: IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {},
),
),
Text('asdasdasdasd'),
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () {},
),
],
),
还有你的第二个问题,两行之间的空间是因为第二行中的图标按钮大小,将其更改为:
SizedBox(
height: 24,
width: 24,
child: IconButton(
padding: EdgeInsets.zero,
icon: const Icon(Icons.refresh),
onPressed: () {},
),
),
只需在日期文本中添加一些左填充,
Padding(
padding:EdgeInsets.only(left: 30),
child:Text(DateFormat('d/M/y').format(DateTime.now()).toString()),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.