简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM