1

Hi friends i am new to the flutter development here i am using the list view please find this image

Please check this image

Where i am want to remove the white space above and below the image make it stretch on this white spaces i am tried to sized box but its given error that double.infinity cant be used please find the below code please help me out friends

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,
          ),
        ),
Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73

3 Answers3

0

You can edit the line

fit: BoxFit.cover

to

fit: BoxFit.fitHeight

inside you container that grabs image from network.

Aman Malhotra
  • 3,068
  • 2
  • 18
  • 28
  • You need to give a sample link so that i can try your code and see what i can do so the image fits in the height .but i still think that the above code i told you to change should have worked just fine . – Aman Malhotra Jul 19 '18 at 11:22
0

I think you are trying to put a list inside another list, so the error shows you can put the list (nested list which is inside the list) in a container and specify a height :

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

        )
      ],
    );
)
  • no its the builder class where i am building the single list item in it – Developers NTS Jul 19 '18 at 01:18
  • yes I can see that, "SliverList" is a list (main list). then you put inside the card a "Column" which is a list. both of them are lists. Doing this "a list inside a list" will cause you that error " infinity height in the listview" – Yousuf AL-Mawali Jul 19 '18 at 01:37
0

If you have a ListView with vertical scroll direction, and want it to have a infinity height, maybe you don't need a ListView.

You can use a regular Column.

vinibrsl
  • 6,563
  • 4
  • 31
  • 44