Flutter How To Get Json Result Length
I'm new to flutter and I'm stuck using the carousel flutter swiper. I need help how to get the length of the json results to use with looping image.network. Here is my code: iklan
Solution 1:
You need to exchange the order of Swiper
and FutureBuilder
in the build() method:
@override
Widget build(BuildContext context) {
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new ConstrainedBox(
child: FutureBuilder<Map<String, dynamic>>(
future: getData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return new Swiper(
itemBuilder: (BuildContext context, int index) {
return new Image.network(
"http://mysite.go.id/wp/gambar_iklan/" +
snapshot.data.data[index].gambar_iklan,
fit: BoxFit.fitWidth,
);
},
itemCount: snapshot.data.length,
viewportFraction: 0.8,
autoplay: true,
scale: 0.9,
itemHeight: MediaQuery.of(context).size.width / 6);
} else {
return new CircularProgressIndicator();
}
},
),
constraints: new BoxConstraints.loose(
new Size(MediaQuery.of(context).size.width, 170.0)),
),
],
);
}
Post a Comment for "Flutter How To Get Json Result Length"