This is the api where I want to fetch the images. I copied that url in the request part and when trying to render them on the screen it tells me that it expected a string but it found a dynamic list. I tried a tostring() but I really don't know.
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
class Api extends StatefulWidget {
var url = Uri.parse("https://dog.ceo/api/breed/hound/images");
Future<dynamic> getdogs() async {
final respuesta = await http.get(url);
if (respuesta.statusCode == 200) {
//print(jsonDecode(respuesta.body));
return (jsonDecode(respuesta.body));
} else {
print("Error con la respusta");
}
}
//Api({Key? key}) : super(key: key);
@override
State<Api> createState() => _ApiState();
}
class _ApiState extends State<Api> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: FutureBuilder(
future: widget.getdogs(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
return Column(
children: [
Image.network(snapshot.data["message"]
),
//Text("${snapshot.data["status"]}"),
],
);
} else {
return CircularProgressIndicator();
}
},
),
),
);
}
}
The error message is correct,
snapshot.data["message"]
it gives you a list of "dynamic" objects, that is, maps, and you are passing that toImage.network
what expects only a String with the URL.Test
And it will work for you, showing you the first image, now, if you want to show a List of images you need to use a
ListView
.More info: https://api.flutter.dev/flutter/widgets/ListView-class.html