I wanna show the images that are from list in another dart file but it won't display anything instead it shows the loading icon, however I used (future, futurebuilder, expended and builder in listview.builder ) As shown in the code !! whatever i tried it showed an exception as followed a little piece of it: (RenderFlex children have non-zero flex)
SingleChildScrollView(
child: FutureBuilder(
future: _getimages(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? Expanded(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
),
Container(
height: 100,
width: 500,
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
padding: const EdgeInsets.all(20),
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
List reslist = snapshot.data;
children:
[
Card(
child: Center(
child: Container(
child: ClipRRect(
borderRadius:
BorderRadius.circular(20),
child: Image.asset(
reslist[index].toString(),
fit: BoxFit.cover,
width: 500,
height: 500,
)),
),
),
elevation: 10,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(15),
),
),
];
return Center(
child: CircularProgressIndicator());
}),
),
],
),
)
: Center(child: CircularProgressIndicator());
}),
),
the output: enter image description here
CodePudding user response:
You should remove the children
from the ListView.builder
, and the Card
should be returned instead of a CircularProgressIndicator
. children
is needed for ListView
not its builder
variant.
CodePudding user response:
this is beacuse you're returning a CircularProgressIndicator insead of Card just do the following changes to your code
SingleChildScrollView(
child: FutureBuilder(
future: _getimages(),
builder: (context, AsyncSnapshot snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? Expanded(
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10, vertical: 10),
),
Container(
height: 100,
width: 500,
child: ListView.builder(
scrollDirection: Axis.horizontal,
shrinkWrap: true,
padding: const EdgeInsets.all(20),
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
List resList = snapshot.data;
return Card(
child: Center(
child: Container(
child: ClipRRect(
borderRadius:
BorderRadius.circular(20),
child: Image.asset(
resList[index].toString(),
fit: BoxFit.cover,
width: 500,
height: 500,
)),
),
),
elevation: 10,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(15),
),
);
}),
),
],
),
)
: Center(child: CircularProgressIndicator());
}),
)