Ser*_*ayi 3 styles row alignment flutter iconbutton
我Row在 Flutter 应用程序中有这个小部件,带有一些IconButtons
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(Icons.skip_previous,
color: Colors.amber, size: 35),
onPressed: () {
setState(() {
pageIndex = 1;
});
}),
IconButton(
icon: Icon(Icons.arrow_left,
color: Colors.amber, size: 45),
onPressed: decIndex),
Text('Page $pageIndex',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.amber,
fontSize: 20,
fontWeight: FontWeight.bold)),
IconButton(
icon: Icon(Icons.arrow_right,
color: Colors.amber, size: 45),
onPressed: () {
incIndex(pageNumbers);
}),
IconButton(
icon: Icon(Icons.skip_next,
color: Colors.amber, size: 35),
onPressed: () {
setState(() {
pageIndex = pageNumbers;
});
}),
IconButton(
icon: Icon(Icons.location_searching,
color: Colors.amber, size: 35),
onPressed: () {
setState(() {
pageIndex = userPage;
});
}),
],
),
Run Code Online (Sandbox Code Playgroud)
它们的显示如下图所示:
红线只是为了清楚标高之间的差异
我想让所有项目通过其中心在同一条线上对齐。我怎样才能做到这一点?
对于小部件来说,使用size参数Icon并不是一个很好的方法IconButton。您的图标变得很大,而IconButtons 不适应扩大的尺寸,这导致图标溢出。
相反,请使用iconSize上的参数IconButton并为 赋予相同的值Icon,然后将其从 中删除Icon。
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
iconSize: 35,
icon: Icon(Icons.skip_previous, color: Colors.amber),
onPressed: () {
setState(() {
pageIndex = 1;
});
}
),
IconButton(
iconSize: 45,
icon: Icon(Icons.arrow_left, color: Colors.amber),
onPressed: decIndex
),
Text('Page $pageIndex',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.amber,
fontSize: 20,
fontWeight: FontWeight.bold)),
IconButton(
iconSize: 45,
icon: Icon(Icons.arrow_right, color: Colors.amber),
onPressed: () {
incIndex(pageNumbers);
}),
IconButton(
iconSize: 35,
icon: Icon(Icons.skip_next, color: Colors.amber),
onPressed: () {
setState(() {
pageIndex = pageNumbers;
});
}),
IconButton(
iconSize: 35,
icon: Icon(Icons.location_searching, color: Colors.amber),
onPressed: () {
setState(() {
pageIndex = userPage;
});
}
)
],
),
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
581 次 |
| 最近记录: |