Flutter の列に ListView を追加するにはどうすればいいですか? 質問する

Flutter の列に ListView を追加するにはどうすればいいですか? 質問する

Flutter アプリ用のシンプルなログイン ページを作成しようとしています。TextField とログイン/サインイン ボタンは正常に作成できました。水平方向の ListView を追加したいと思います。コードを実行すると要素が消えますが、ListView なしで実行すると、再び正常になります。これを正しく行うにはどうすればよいですか?

return new MaterialApp(
        home: new Scaffold(
          appBar: new AppBar(
            title: new Text("Login / Signup"),
          ),
          body: new Container(
            child: new Center(
              child: new Column(
              mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  new TextField(
                    decoration: new InputDecoration(
                      hintText: "E M A I L    A D D R E S S"
                    ),
                  ),
                  new Padding(padding: new EdgeInsets.all(15.00)),
                  new TextField(obscureText: true,
                    decoration: new InputDecoration(
                      hintText: "P A S S W O R D"
                    ),
                    ),
                  new Padding(padding: new EdgeInsets.all(15.00)),
                  new TextField(decoration: new InputDecoration(
                    hintText: "U S E R N A M E"
                  ),),
                  new RaisedButton(onPressed: null,
                  child:  new Text("SIGNUP"),),
                  new Padding(padding: new EdgeInsets.all(15.00)),
                  new RaisedButton(onPressed: null,
                  child: new Text("LOGIN"),),
                  new Padding(padding: new EdgeInsets.all(15.00)),
                  new ListView(scrollDirection: Axis.horizontal,
                  children: <Widget>[
                    new RaisedButton(onPressed: null,
                    child: new Text("Facebook"),),
                    new Padding(padding: new EdgeInsets.all(5.00)),
                    new RaisedButton(onPressed: null,
                    child: new Text("Google"),)
                  ],)

                ],
              ),
            ),
            margin: new EdgeInsets.all(15.00),
          ),
        ),
      );

ベストアンサー1

私も同じ問題を抱えています。私の解決策は、Expandedウィジェットを使用して残りのスペースを拡張することです。

Column(
  children: <Widget>[
    Expanded(
      child: horizontalList,
    )
  ],
);

おすすめ記事