Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Hi,i have this probleme in flutter,i want fetch api with listview builder but they show this error after 2 seconds i got my data

enter image description here

//listviewBuilder

return Container(
height: 380,
child: ListView.builder(
padding: EdgeInsets.symmetric(vertical: 8.0),
scrollDirection: Axis.horizontal,
itemCount: listtest.length,
itemBuilder: (context, index) {
return index == listtest[index]
? SizedBox(
width: 10,
)
: Card(
margin: EdgeInsets.only(right: 8.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(10.0))),
child: Container(
height: 400,
width: 370,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
onTap: () {
Navigator.pushNamed(context, ‘HouseDetails’);
},
child: Container(
height: 260,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: AssetImage(images[index])),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
)),
),
),
Container(
padding: EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
listtest[index][‘name’].toString(),
style: kh4,
),
SizedBox(
height: 2,
),
Text(
addresses[index],
style:
TextStyle(color: Colors.grey, fontSize: 10),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
SizedBox(
height: 2,
),
IntrinsicHeight(
child: Row(
children: [
Text(
‘3 ‘,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12),
),
Text(
‘bds ‘,
style: TextStyle(fontSize: 12),
),
VerticalDivider(
width: 1,
color: Colors.grey,
),
Text(
‘ 5 ‘,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12),
),
Text(
‘baths ‘,
style: TextStyle(fontSize: 12),
),
VerticalDivider(
width: 1,
color: Colors.grey,
),
Text(
‘ 1750 ‘,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 12),
),
Text(
‘sqft’,
style: TextStyle(fontSize: 12),
),
],
),
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 7,
),
Text(
‘Starting Price’,
style: TextStyle(
fontSize: 12,
),
),
Text(
prices[index],
style: TextStyle(
color: primaryColor,
fontWeight: FontWeight.bold,
fontSize: 11),
)
],
),
Spacer(),
HeartContainer(index)
],
)
],
),
)
],
),
),
);
}),
);

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It seems to me listtest can be null. You should make sure you take that into account.

Try replacing listtest.length with listtest?.length ?? 0

and

listtest[index] with listtest?.elementAt(index)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading