我正在尝试在卡片小部件中的某些文本和图标的顶部和底部添加一些填充。我发现 flutter 有一种简单的方法可以为容器执行此操作,但似乎无法找到使用其他小部件执行此操作的方法(除了将它们包装在容器中)。这是我目前得到的代码:
body: new Container(
padding: new EdgeInsets.all(10.0),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget> [
new Card(
color: Colors.white70,
child: new Container(
padding: new EdgeInsets.all(10.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget> [ //Padding between these please
new Text("I love Flutter", style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold)),
new Icon(Icons.favorite, color: Colors.redAccent, size: 50.0)
]
)
)
)
]
)
)
因此,在我的子列中,我想在顶部和底部添加一些填充,而不必插入新的容器。这可能吗?
最佳答案
你可以使用Padding
,这是一个非常简单的Widget
,它只需要另一个Widget
作为child
和一个 EdgeInsets
对象,就像您已经用作 padding
的对象一样。
Flutter 中这种“组合优于继承”的做法是非常有意的。你可以在 Flutter 的 Gitter channel 上找到最近关于利弊的讨论。 .
https://stackoverflow.com/questions/44053363/