'infinity height in the listview of the flutter
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,
),
),
Solution 1:[1]
You can edit the line
fit: BoxFit.cover
to
fit: BoxFit.fitHeight
inside you container that grabs image from network.
Solution 2:[2]
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")
],
),
)
],
);
)
Solution 3:[3]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aman Malhotra |
| Solution 2 | Yousuf AL-Mawali |
| Solution 3 | Vinicius Brasil |
