在堆栈中填充所有可用的水平 space
Fill all available horizontal space in a stack
在卡片中,我有一个堆栈,其中包含 1) 图像和 2) 容器中的文本。
如何让容器的宽度填满卡片的宽度?
Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Positioned.fill(child: Image.network(
image_url,
fit: BoxFit.fitWidth,
),
),
Positioned(
bottom: 0,
child: Container(
padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
decoration: new BoxDecoration(color: Colors.black12),
child: Row(
children: <Widget>[
Text("test1"),
Text("test2"),
Text("test3"),
],
),
),
),
],
)
);
用 Expanded
小部件包裹所有孩子。
Row(
children: <Widget>[
Expanded(
child: Text("test1")
),
Expanded(
child: Text("test2")
),
Expanded(
child: Text("test3")
),
],
),
来自Expanded Widget Documentation:
Using an Expanded widget makes a child of a Row, Column, or Flex expand to fill the available space in the main axis (e.g., horizontally for a Row or vertically for a Column). If multiple children are expanded, the available space is divided among them according to the flex factor.
将 left
和 right
的值设置为 0
以便容器的行为如此。
Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Positioned.fill(child: Image.network(
image_url,
fit: BoxFit.fitWidth,
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
decoration: new BoxDecoration(color: Colors.black12),
child: Row(
children: <Widget>[
Text("test1"),
Text("test2"),
Text("test3"),
],
),
),
),
],
)
);
在卡片中,我有一个堆栈,其中包含 1) 图像和 2) 容器中的文本。 如何让容器的宽度填满卡片的宽度?
Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Positioned.fill(child: Image.network(
image_url,
fit: BoxFit.fitWidth,
),
),
Positioned(
bottom: 0,
child: Container(
padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
decoration: new BoxDecoration(color: Colors.black12),
child: Row(
children: <Widget>[
Text("test1"),
Text("test2"),
Text("test3"),
],
),
),
),
],
)
);
用 Expanded
小部件包裹所有孩子。
Row(
children: <Widget>[
Expanded(
child: Text("test1")
),
Expanded(
child: Text("test2")
),
Expanded(
child: Text("test3")
),
],
),
来自Expanded Widget Documentation:
Using an Expanded widget makes a child of a Row, Column, or Flex expand to fill the available space in the main axis (e.g., horizontally for a Row or vertically for a Column). If multiple children are expanded, the available space is divided among them according to the flex factor.
将 left
和 right
的值设置为 0
以便容器的行为如此。
Card(
clipBehavior: Clip.antiAlias,
child: Stack(
children: <Widget>[
Positioned.fill(child: Image.network(
image_url,
fit: BoxFit.fitWidth,
),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: Container(
padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
decoration: new BoxDecoration(color: Colors.black12),
child: Row(
children: <Widget>[
Text("test1"),
Text("test2"),
Text("test3"),
],
),
),
),
],
)
);