我正在尝试使用 Flutter 创建一个带有图标和标题的卡片小部件。但是我无法在卡片边框和小部件之间添加一些边距。
这是我的卡代码:
class MyCard extends StatelessWidget{
MyCard({this.title, this.icon});
final Widget title;
final Widget icon;
@override
Widget build(BuildContext context) {
return new Container(
padding: EdgeInsets.only(bottom: 20.0),
child: new Card(
child: new Row(
children: <Widget>[
this.icon,
new Container(
width: 20.0, //I also don't know if this is legal
),
this.title
]
)
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是结果,但我想在卡片内部有更多的填充,以便有更高的卡片和更多的图标在右边。
ap1*_*p14 13
您可以将小部件包装在Padding小部件内的卡片中,也可以使用容器的padding或margin属性来实现所需的布局。
PS 我在不同级别添加了填充。根据您的需要删除或添加更多填充。
代码:
class MyCard extends StatelessWidget{
MyCard({this.title, this.icon});
final Widget title;
final Widget icon;
@override
Widget build(BuildContext context) {
return new Container(
padding: EdgeInsets.only(bottom: 20.0),
child: new Card(
child: Padding(
padding: EdgeInsets.symmetric(vertical: 2.0),
child: new Row(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 5.0),
child: this.icon,
),
new SizedBox(
width: 20.0,
),
Container(
padding: EdgeInsets.symmetric(vertical: 0.5, horizontal: 1.0),
margin: EdgeInsets.all(2.0),
child: this.title,
)
]
),
)
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19893 次 |
| 最近记录: |