下面是顯示正文下方按鈕的部分代碼。
......
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("One button"),
),
),
SizedBox(
//space between button
width: 5,
),
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("Two button"),
),
),
],
),
)
......
但問題是按鈕的寬度是為整個頁面獲取的。而且我希望它限制在身體的寬度BoxConstraints(maxWidth: 800)。
在照片中,我用紅色邊框標記了所需的按鈕寬度。我怎樣才能做到這一點。

uj5u.com熱心網友回復:
你用ConstrainedBox.
ConstrainedBox(
constraints: BoxConstraints(maxWidth: 800),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("One button"),
),
),
SizedBox(
//space between button
width: 5,
),
Expanded(
child: OutlinedButton(
onPressed: () {},
child: Text("Two button"),
),
),
],
),
),
)
如果您想避免填充,可以將其洗掉或使用ConstrainedBoxon Row。
uj5u.com熱心網友回復:
您可以添加 2 個擴展小部件并使用該flex屬性。展開,彎曲
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
flex: 10,
child: Container(),
),
Expanded(
flex: 40,
child: OutlinedButton(
onPressed: () {},
child: Text("One button"),
),
),
SizedBox(
//space between button
width: 5,
),
Expanded(
flex: 40,
child: OutlinedButton(
onPressed: () {},
child: Text("Two button"),
),
),
Expanded(
flex: 10,
child: Container(),
),
],
),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/442448.html
