Флаттер: все виджеты должны располагаться вертикально в контейнере - PullRequest
0 голосов
/ 09 января 2019

Я хочу расположить все элементы вертикально в контейнере, я взял в ряд и так же хорошо, как в столбце, но не могу расположить вертикально, как 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 голосов
/ 09 января 2019

Я не знаю, какое у вас точное требование к макету - Если я понял ваш вопрос - Попробуйте этот код:

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...