颤抖:所有小部件都应在容器中垂直排列

时间:2019-01-09 12:17:43

标签: android dart flutter containers

我想将所有物品垂直放置在容器中,我已经像在Coloum中一样连续放置了孔,但无法像Linear Layout垂直放置那样垂直放置。

void main() {
      runApp(new MaterialApp(
        title: "My Demooo2",
        home: new MyScaffold(),
      ));
    }

class MyBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Container(
      height: 90.0,
      margin: new EdgeInsets.symmetric(vertical: 20.0),
      padding: new EdgeInsets.all( 8.0),
      decoration: new BoxDecoration(color: Colors.blue[100]),
      child: new Row(
        children: <Widget>[
          new IconButton(icon: new Icon(Icons.adjust), onPressed: null),
          new IconButton(icon: new Icon(Icons.disc_full), onPressed: null),
          new IconButton(icon: new Icon(Icons.scatter_plot), onPressed: null),
          new IconButton(icon: new Icon(Icons.delete_forever), onPressed: null),
          new Text("test")
        ],
      ),
    );
  }
}

class MyScaffold extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Material(
      child: new Column(
        children: <Widget>[
          new MyBar(),
          new Expanded(
              child: new Center(
            child: new Text("My Center"),
          ))
        ],
      ),
    );
  }
}

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

我不知道您的确切布局要求-如果我理解您的问题-请尝试以下代码:

class MyBar extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Container(
    //  height: 90.0,
      margin: new EdgeInsets.symmetric(vertical: 20.0),
      padding: new EdgeInsets.all( 8.0),
      decoration: new BoxDecoration(color: Colors.blue[100]),
      child: new Column(
        children: <Widget>[
          new IconButton(icon: new Icon(Icons.adjust), onPressed: null),
          new IconButton(icon: new Icon(Icons.disc_full), onPressed: null),
          new IconButton(icon: new Icon(Icons.scatter_plot), onPressed: null),
          new IconButton(icon: new Icon(Icons.delete_forever), onPressed: null),
          new Text("test")
        ],
      ),
    );
  }
}

class MyScaffold extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Material(
      child: new Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          new MyBar(),
          new Expanded(
              child: new Center(
                child: new Text("My Center"),
              ))
        ],
      ),
    );
  }
}

输出:

enter image description here