颤振列表视图中的无穷高

时间:2018-07-18 18:35:11

标签: dart flutter flutter-layout flutter-sliver

嗨,朋友们,我是flutter开发的新手,我正在使用列表视图,请找到这张图片Please check this image,在这里我要删除图片上方和下方的空白,使其在此空白上伸展。尝试调整尺寸,但无法使用double.infinity的给定错误,请找到以下代码,请帮帮我的朋友

new SliverList(
          delegate: new SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return new GestureDetector(
                onTap: () {
                  Navigator.push(
                      context,
                      new MaterialPageRoute(
                          builder: (context) => new News_Details(
                                postid: latest_news_list[index]['id'],
                              )));
                },
                child: new Card(
                  elevation: 4.0,
                  margin: EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0),
                  child: new Row(
                    children: <Widget>[
                      **new Container(
                        child: new Image.network(
                          latest_news_list[index]['image'],
                          width: 150.0,
                          fit: BoxFit.cover,
                        ),
                      ),**
                      new Flexible(
                        child: new Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: <Widget>[
                            new Container(
                              child: new Text(latest_news_list[index]['title']),
                              margin: EdgeInsets.only(left: 10.0, top: 10.0),
                            ),
                            new Container(
                              child: new Divider(
                                color: secondarycolor,
                              ),
                              margin: EdgeInsets.only(right: 10.0, left: 10.0),
                            ),
                            new Container(
                              child: new Text(
                                latest_news_list[index]['content'],
                                softWrap: true,
                                maxLines: 4,
                              ),
                              margin: EdgeInsets.only(
                                  left: 10.0, top: 5.0, bottom: 5.0),
                            ),
                            new Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: <Widget>[
                                new Container(
                                  child: new Text('VSB News'),
                                  margin:
                                      EdgeInsets.only(left: 10.0, top: 10.0,bottom: 10.0),
                                ),
                                new Container(
                                  child: new Text(
                                      latest_news_list[index]['post_dt']),
                                  margin:
                                      EdgeInsets.only(left: 10.0, top: 10.0,right: 10.0,bottom: 10.0),
                                ),
                              ],
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              );
            },
            childCount: latest_news_list == null ? 0 : latest_news_list.length,
          ),
        ),

3 个答案:

答案 0 :(得分:0)

您可以编辑行

fit: BoxFit.cover

fit: BoxFit.fitHeight

在您的容器内部,该容器从网络抓取图像。

答案 1 :(得分:0)

我认为您正在尝试将一个列表放在另一个列表中,因此错误显示 您可以将列表(列表内的嵌套列表)放在容器中并指定高度:

 ListView _buildMainView(){

    return new ListView(
      children: <Widget>[
        new Text("Main List"),
        new Container(
          height: 100.0,
          child: new ListView(
            children: <Widget>[
              new Text("Nested List")
            ],
          ),

        )
      ],
    );
)

答案 2 :(得分:0)

如果您的ListView具有垂直滚动方向,并且希望它具有无限的高度,则也许您不需要ListView

您可以使用常规的Column