如何左对齐OutlineButton
颤振中的图标?Icon
可以按如下方式添加,但图标和文本都在按钮中居中对齐。有没有办法将图标向左对齐,文本向中心对齐?
return new OutlineButton.icon(
onPressed: onPressed,
label: new Text(title),
icon: icon,
highlightedBorderColor: Colors.orange,
color: Colors.green,
borderSide: new BorderSide(color: Colors.green),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(5.0)));
有很多方法可以做到这一点,但使用您提到的工厂构造函数是不可能的OutlinedButton.icon
,您可以更深入地检查源代码,看看它是如何构建小部件的。
您可以创建自己的Widget
将图标放在左侧并使文本居中。
您也可以使用OutlinedButton
小部件并传递 Stack/Row 作为子项,请检查此示例
OutlinedButton(
onPressed: () => null,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Icon(Icons.access_alarm)
),
Align(
alignment: Alignment.center,
child: Text(
"Testing",
textAlign: TextAlign.center,
)
)
],
),
highlightedBorderColor: Colors.orange,
color: Colors.green,
borderSide: new BorderSide(color: Colors.green),
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(5.0)
)
)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)