Flutter - 在另一个小部件下方定位列表视图

12

我刚开始学习Flutter,遇到了一个布局问题,这里提供一个视觉示例:

图片描述

我已经尝试过以下方法:

        class MyApp extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return new MaterialApp(
              title: 'Welcome to Flutter',
              home: new Scaffold(
                  appBar: new AppBar(
                    title: new Text('App'),
                  ),
                  body: new Column(
                      children: <Widget>[
                        new Text('LISTA',
                            style: new TextStyle(
                              fontSize: 15.2,
                              fontWeight: FontWeight.bold,
                            )
                        ),
                        new Container(
                          height: 200.0,
                          child: new ListView(
                            children: <Widget>[
                              new RaisedButton(
                                onPressed: null,
                                child: new Text("text button"),
                              ),
                              new Padding(padding: new EdgeInsets.all(5.00)),
                              new RaisedButton(
                                onPressed: null,
                                child: new Text("text button 2"),
                              )
                            ],
                          ),
                        )
                      ]
                  )
              ),
            );
          }
        }

但是对于容器,它需要一个高度,并且我希望它占据整个屏幕的剩余空间。


可能是创建一个固定的网站页脚的重复问题。 - Rémi Rousselet
1
你想要的是第二种解决方案,即使用 Expanded 小部件。 - Rémi Rousselet
扩展解决了我的问题。谢谢! - Paulo Gonçalves
请问您能否在答案中展示代码?我遇到了同样的问题,而且展开(expanded)也对我不起作用。 - Ammy Kang
@AmmyKang 我已将代码发布为答案。 - Paulo Gonçalves
感谢 @PauloGonçalves, - Ammy Kang
1个回答

17
new Column(
    children: <Widget>[
        new Text('LISTA', style: new TextStyle(
            fontSize: 15.2,
            fontWeight: FontWeight.bold,
        )),
        new Expanded(
            child: new Container(
                decoration: new BoxDecoration(color: Colors.blue),
                child: new ListView(
                    children: <Widget>[
                        new RaisedButton(
                            onPressed: null,
                            child: new Text("text button"),
                        ),
                        new Padding(padding: new EdgeInsets.all(5.00)),
                        new RaisedButton(
                            onPressed: null,
                            child: new Text("text button 2"),
                        )
                    ],
                ),
            )
        )
    ]
)

Container小部件中的“height”参数是不必要的。 - Achintha Isuru
谢谢您,Archintha :) - Paulo Gonçalves

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接