Ale*_*Ale 3 tabular flutter flutter-layout
我想得到这个结构:
-----------------------------------------------------------------------------------
item 1 item 2
item 3 item 4
-----------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)
基本上我需要一个Table带2 columns的2 rows,每个2 column,但这是我得到的效果:
我的代码:
new Container(
decoration: new BoxDecoration(color: Colors.grey),
child: new Row(
children: <Widget>[
new Column(
children: <Widget>[
new Container(
decoration: new BoxDecoration(color: Colors.red),
child: new Text("item 1"),
),
new Container(
decoration: new BoxDecoration(color: Colors.amber),
child: new Text("item 3"),
),
],
),
new Column(
children: <Widget>[
new Container(
decoration: new BoxDecoration(color: Colors.green),
child: new Text("item 2"),
),
new Container(
decoration: new BoxDecoration(color: Colors.teal),
child: new Text("item 4"),
)
],
)
],
),
)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我希望每个人column都占用一半的width空间.在Android我使用该weight属性,就是这样.
N. *_* T. 17
我建议使用Table Widget来保持一致性和易用性,因为嵌套的行和列可能会有些混乱并且缩进很远。
https://docs.flutter.io/flutter/widgets/Table-class.html
...
Table(children: [
TableRow(children: [
Text("item 1"),
Text("item 2"),
]),
TableRow(children:[
Text("item 3"),
Text("item 4"),
]),
]);
Run Code Online (Sandbox Code Playgroud)
使用flex(默认情况下为1)您可以将两列分开,然后使用crossAxisAlignment它们在开头对齐它们:

new Container(
decoration: new BoxDecoration(color: Colors.grey),
child: new Row(
children: <Widget>[
Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
decoration: new BoxDecoration(color: Colors.red),
child: new Text("item 1"),
),
new Container(
decoration: new BoxDecoration(color: Colors.amber),
child: new Text("item 3"),
),
],
),
),
Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Container(
decoration: new BoxDecoration(color: Colors.green),
child: new Text("item 2"),
),
new Container(
decoration: new BoxDecoration(color: Colors.teal),
child: new Text("item 4"),
)
],
),
)
],
),
)
Run Code Online (Sandbox Code Playgroud)