Jan
Jan

Reputation: 2522

How to get Flutter web to listen on 127.0.0.1

I'm trying to get my Flutter app to work on web but I need it running on a specific hostname. When I run flutter run -d chrome it opens it on http://[::1]:57402/#/ (or some other random port)

If I change it http://localhost:57402/#/ it is still working as expected.

But now if I change it to http://127.0.0.1:57402/#/ I get a connection refused error. So if I need to change the hosts file to use a different name, that's also not working (I'm assuming because the 127.0.0.1 ip that I'm using in the hosts file is not working)

So any idea why this is happening or how can I make it work?

Upvotes: 11

Views: 11145

Answers (1)

Spatz
Spatz

Reputation: 20118

We can specify host with web-hostname and port with web-port parameters:

flutter run -d chrome --web-hostname 127.0.0.1 --web-port 8888

The most reliable source of information is the flutter tools source code.

Upvotes: 20

Related Questions