Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

782
Visualizações
My flutter app fails to connect to FastApi

I have been trying for ages and can't figure it out, I hope you can help me. I have my SQL database running as well as FastApi. FastAPI is running on: http://127.0.0.1:8000 <- as seen here

And it works perfectly when testing on OpenApi as shown here.

I have my flutter app making the the following get request:

    Future MakeGetProductRequest() async {
    Uri url = Uri.parse('http://localhost:8000/items?page=1&number=5');
    var response = await http.get(url);
    return response;
    }

When running the app on a physical device through USB-debugging, I get the following Error:

 Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 34214

Full console error here

NOTE: I am running this on a physical device not an emulator!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It won't work on the loopback address. Your address 127.0.0.1 is not accessible on the flutter device.

To connect both of them, you will have to run FastAPI on 0.0.0.0 like this:

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

The above code will make your local IP available over the LAN. Just make sure your phone and PC are connected to the same WIFI network.

To get your PC's IP address, run this in command prompt:

ipconfig

And you will get output like this:

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . :
   IPv4 Address. . . . . . . . . . . : 192.168.29.82
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.29.1

You can see my IPv4 Address is 192.168.29.82 so, to access FastAPI from my flutter code, I will have to connect to http://192.168.29.82:8000

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda