I want to use a FutureBuilder to check if a url is a png image, and then build either one or two images(in a list). But somehow the Future always returns null when i print it...
The result is the app always building the listview with the two CachedNetworkImages, which is not what i want it to do. If the URL is an image, it should just build a CachedNetworkImage with that url, and if not it should alter the url and build a listview with 2 images.
child: new FutureBuilder(
future: _getImages(widget.imgUrl),
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
return new Text('Press button to start');
case ConnectionState.waiting:
return new Text('Awaiting result...');
default:
if (snapshot.hasError)
return new Text('Error: ${snapshot.error}');
else {
print(snapshot.data);
if (snapshot.data == "image/png") {
return new SingleChildScrollView(
child: new CachedNetworkImage(
imageUrl: widget.imgUrl,
placeholder: new Center(
child: new AdaptiveProgressIndicator()),
),
);
} else {
return new ListView(
children: <Widget>[
new CachedNetworkImage(
imageUrl:
widget.imgUrl.split('.png')[0] + '-0.png',
placeholder: new Center(
child: new AdaptiveProgressIndicator()),
),
new CachedNetworkImage(
imageUrl:
widget.imgUrl.split('.png')[0] + '-1.png',
)
],
);
}
}
}
}),
),
));
}
Future<String> _getImages(String url) async {
await http.get(url).then((result) {
return result.headers['content-type'];
});
}