I am very new to Flutter, and stuck at the following problem:
My function to get a list of books using googleapis:
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";
});
}
In pubspec.yaml
I have
http: ^0.13.4
It seems to me that the get method is not being called, or maybe the call is pending
Sorry the code isn't in English
CodePudding user response:
try adding "http" or "https" to dominio, like:
final String dominio = "http://www.googleapis.com"
or
final String dominio = "https://www.googleapis.com"
CodePudding user response:
I solved the problem call effect it works but it fails 'immagineCopertina' which sometimes returns null I added a control in Image.newtork by putting a dummy url if 'immagineCopertina' is null