[英]Button with text above and below icon
I'm trying to make a widget achieve the following effect: 我正在尝试使小部件达到以下效果:
It's a button that shows a icon on the middle and text above or below the icon depending if it's inverted or not. 它是一个按钮,在中间显示一个图标,并在该图标的上方或下方显示文本,具体取决于该图标是否被反转。
I did the following to add the icon and the text to the button: 我做了以下操作,将图标和文本添加到按钮:
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
isInverted
? Icon(Icons.access_alarm)
: Text("Test")
isInverted
? Padding(padding: EdgeInsets.only(top: 20))
: Padding(padding: EdgeInsets.only(top: 20)),
isInverted
? Text("Test")
: Icon(Icons.access_alarm),
isInverted
? Padding(padding: EdgeInsets.only(top: 0))
: Padding(padding: EdgeInsets.only(bottom: 20)),
],
),
The problem is that the buttons aren't symmetric. 问题在于按钮不是对称的。
It works fine if the button isn't inverted but if it is the icon isn't centered. 如果按钮未反转但图标未居中,则效果很好。
And maybe there is a solution without using any padding. 也许有一种不使用任何填充的解决方案。
Try this way 试试这个
child: RaisedButton(
shape: Border.all(width: 2.0),
onPressed: _onPressed,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.center,
child: Icon(Icons.home),
),
Align(
alignment:
isInverted ? Alignment.bottomCenter : Alignment.topCenter,
child: Text("home"),
)
],
),
)
Also suggested by @ishaan 也由@ishaan建议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.