我正在尝试在卡片小部件中的某些文本和图标的顶部和底部添加一些填充。我发现颤振有一种简单的方法可以为容器执行此操作,但似乎无法找到使用其他小部件执行此操作的方法(除了将它们包装在容器中)。这是我到目前为止的代码:
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)
]
)
)
)
]
)
)
所以在我的列子中,我想在顶部和底部添加一些填充,而不必插入新的容器。这可能吗?
原文由 Bram Vanbilsen 发布,翻译遵循 CC BY-SA 4.0 许可协议
You can use
Padding
, which is a very simpleWidget
that just takes anotherWidget
as achild
and anEdgeInsets
像您已经使用的对象一样padding
。Flutter 中这种“组合优于继承”的做法是非常有意的。你可以在 Flutter 的 Gitter 频道 上找到最近关于利弊的讨论。