我对Flutter很陌生,并且一直在解决以下问题:
我使用谷歌API获取图书列表的功能:
Future cercaLibri(String ricerca) async {
final String dominio = 'www.googleapis.com';
final String percorso = '/books/v1/volumes';
Map<String, dynamic> parametri = {'q': ricerca};
final Uri url = Uri.https(dominio, percorso, parametri);
print('hello');
http.get(url).then((res) {
final resJson = json.decode(res.body);
final libriMap = resJson['items'];
libri = libriMap.map<Libro>((value) => Libro.fromMap(value)).toList();
setState(() {
libri = libri;
risultato = res.body;
});
});
setState(() {
risultato = "Caricamento in corso";
});
}
对于所有文件,请参阅stackblitz
在pubspec.yaml
中,我有
http: ^0.13.4
在我看来,get方法没有被调用,或者调用正在等待
抱歉代码不是英文
尝试添加"http";或";https";到多明尼欧,比如:
final String dominio = "http://www.googleapis.com"
或
final String dominio = "https://www.googleapis.com"
我解决了这个问题呼叫效果有效但它失败了"immagineCopertina",后者有时返回null如果"immagineCopertina"为空,我在Image.newtork中添加了一个控件,方法是放置一个伪url