Flutter列表视图中的无限高度

72qzrwbm  于 2023-01-31  发布在  Flutter
关注(0)|答案(3)|浏览(176)

嗨,朋友们,我是新的Flutter开发在这里,我使用的列表视图,请找到这张图片

在那里我想删除上面和下面的白色图像,使它在这个空白空间伸展,我试图大小框,但它的给定错误,双。无限不能使用请找到下面的代码,请帮助我的朋友

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,
          ),
        ),
ia2d9nvy

ia2d9nvy1#

您可以编辑该行

fit: BoxFit.cover

fit: BoxFit.fitHeight

在你的容器里从网络上抓取图像。

osh3o9ms

osh3o9ms2#

我认为您试图将一个列表放入另一个列表中,因此错误显示您可以将列表(嵌套列表,位于列表中)放入容器中并指定高度:

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")
            ],
          ),

        )
      ],
    );
)
mutmk8jj

mutmk8jj3#

如果你有一个垂直滚动方向的ListView,并且希望它有一个无限的高度,也许你不需要ListView
您可以使用常规的Column

相关问题