![](/img/trans.png)
[英]How to align widgets left, center, right on single row widget flutter
[英]How to align a widget to the right of a dynamic centered widget in Flutter?
我在中心有一個具有動態寬度的文本小部件。 但是,我想在這個文本小部件的右側添加一個小部件。
因為這個中心文本小部件具有動態寬度,所以我不能使用絕對定位小部件,例如 Align 或 Position 小部件。 我正在尋找類似於 Android 中的 RelativeLayout 的東西。
Widget body() {
return Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Center text'),
FlatButton(
child: Text('next'),
onPressed: () {},
),
],
),
);
}
使用@Igors 方法,我可以以一個中心小部件結束,每端都有一個均勻分布的按鈕。 我的目標是按鈕位於右側。
Widget body() {
return Container(
child: Row(
children: <Widget>[
Expanded(
child: FlatButton(
child: Text('next'),
onPressed: () {},
),
),
Container(color: Colors.red, child: Text('test')),
Expanded(
child: FlatButton(
child: Text('next'),
onPressed: () {},
),
),
],
),
);
}
編輯:通過在居中小部件 1 的每一側使用大小框來解決。
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.green
),
),
Container(
color: Colors.red,
child: Text('test')
),
Expanded(
child: Container(
color: Colors.blue
),
),
],
)
使用小部件行並將文本小部件添加到容器小部件中。
並為容器添加邊距
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.