1

嗨朋友们,我是颤振开发的新手,我正在使用列表视图,请找到这张图片盒子,但它给出的错误是 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,
          ),
        ),
4

3 回答 3

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

        )
      ],
    );
)
于 2018-07-19T01:07:21.750 回答
0

如果您有一个ListView垂直滚动方向,并希望它具有无限高,也许您不需要ListView.

您可以使用常规的Column.

于 2019-06-19T22:03:54.520 回答
0

您可以编辑该行

fit: BoxFit.cover

fit: BoxFit.fitHeight

在从网络获取图像的容器内部。

于 2018-07-18T18:44:20.120 回答