1

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";
        });
      }

for all files see stackblitz

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

1
  • I am able to run this code and able to get the data, Can you make sure that the emulator or device you are running this code has a active internet connection. Commented Mar 16, 2022 at 15:07

2 Answers 2

1

try adding "http" or "https" to dominio, like:

final String dominio = "http://www.googleapis.com"

or

final String dominio = "https://www.googleapis.com"

Sign up to request clarification or add additional context in comments.

1 Comment

no need because I use the Uri.https (...) method, if I insert http / https it goes in error
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.