2017-01-25 3 views
5

ColumnMaterialListであるCardのみからなるページがあります。私のリストには1つまたは2つのアイテムしかない場合でも、リスト項目の最後に停止するのではなく、カードの垂直スペースが画面の最下部まで広がります。 Column documentationは、これが通常の列動作(「各子は無限の垂直方向の拘束を持つゼロまたはフレックスファクタ(例えば、拡張されていないもの)をレイアウトする」)であることを示唆しています。私はFlexibleでリストをラップすることは、私の所望の効果を達成するかもしれないと思ったが、私が試したとき、私は、次のエラーを得た:ウィジェットの列をカードの中にしっかりとラップできますか?

RenderFlex children have non-zero flex but incoming height constraints are unbounded. 
I/flutter (11469): When a column is in a parent that does not provide a finite height constraint, for example if it is 
I/flutter (11469): in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a 
I/flutter (11469): flex on a child (e.g. using a Flexible) indicates that the child is to expand to fill the remaining 
I/flutter (11469): space in the vertical direction. 
I/flutter (11469): These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child 
I/flutter (11469): cannot simultaneously expand to fit its parent. 

私ははっきりと、このレイアウトが動作するようになっている方法について何かを誤解しています。ここで

が、私はこのページのScaffoldのボディとして、今持っているもののサンプルコードです:

new Container(
// Outer container so we can set margins and padding for the cards 
// that will hold the rest of the view. 
alignment: FractionalOffset.topCenter, 
margin: new EdgeInsets.only(top: style.wideMargin), 
padding: new EdgeInsets.symmetric(horizontal: style.defaultMargin), 
child: new Card(
    child: new Column(
    children: [ 
     new CustomHeader(), // <-- a Row with some buttons in it 
     new Divider(), 
     new MaterialList(
     type: MaterialListType.twoLine, 
     children: listItems, // <-- a list of custom Rows 
    ), 
    ], 
), 
), 

どのように私はしっかりとウィジェットのColumnをラップカードを持つことができますか?

答えて

11

デフォルトでは、Columnは、最大縦スペースを埋めるように展開されます。 mainAxisSizeプロパティをMainAxisSize.minに設定すると、Columnは子に合わせるのに必要な最小限の垂直方向のスペースしか占めなくなります。

関連する問題