代码之家  ›  专栏  ›  技术社区  ›  Farhana Naaz Ansari Debashish Dwivedi

颤振:所有部件应垂直排列在容器中。

  •  0
  • Farhana Naaz Ansari Debashish Dwivedi  · 技术社区  · 5 年前

    我想把所有的东西都垂直地放在容器里,我已经把它们排成一行,和列一样,但不能像列那样垂直排列。 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 回复  |  直到 5 年前
        1
  •  0
  •   anmol.majhail    5 年前

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

    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