我正在尝试使用 mediastack api,但出现此错误,我阅读了有关制作动态地图的内容,但我不知道该怎么做,知道吗?
课程代码
class Noticia {
final String autor, titulo, descripcion, urlOrigen, fuente, imagen, categoria, lenguaje, pais, fecha;
Noticia(this.autor, this.titulo, this.descripcion, this.urlOrigen, this.fuente, this.imagen, this.categoria, this.lenguaje, this.pais, this.fecha);
}
应用代码
class _MyHomePageState extends State<MyHomePage> {
getDatos() async{
var response = await http.get(Uri.http('api.mediastack.com', '/v1/news?access_key=73f6b81fabc3ec26a7ec4b5dba80eb2c&keywords=salud&countries=mx&limit=3'));
var jSonData = jsonDecode(response.body);
List<Noticia> noticias = [];
for(var u in jSonData){
Noticia noticia = Noticia(u['author'], u['title'],u['description'],u['url'],
u['source'],u['image'],u['category'],u['language'],u['country'],u['published_at']);
noticias.add(noticia);
}
print(noticias.length);
return noticias;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ElevatedButton(child: Text('Probar'),
onPressed: (){getDatos();},))
);
}
}