Search code examples
flutterapidartinsomnia

Error consuming API on localhost with Flutter


I'm trying to comnsumer API that is on my localhost with Flutter but it's giving the error "OS Error: Connection refused, errno = 111, address = 127.0.0.1, port..."

I'm using the dartion package to run the api on localhost, and the API works fine when testing on Insomnia


Solution

  • If you are trying to consume the API from flutter running in an Android emulator, you should consume it through 10.0.2.2 as this points to the host machine's IP. 127.0.0.1 in the emulator point to the localhost of the emulator thus resulting flutter not to be able to connect to the server.