Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 493
Jan Avatar asked Feb 26 '20 13:02

Jan


People also ask

How do you call a localhost Flutter?

You can tell it to use a fixed port and then that becomes the port you need to include in your allowed origins. Add --web-hostname=localhost --web-port=9999 as command line parameters to where you run your main. dart , then add localhost:9999 as an allowed origin.

Can Flutter run on Web browser?

Flutter web apps can run on the following browsers: Chrome (mobile & desktop) Safari (mobile & desktop) Edge (mobile & desktop)

How can I tell if Flutter app is running on my website?

You can check whether your Flutter app is running on a web browser by using the kIsWeb constant from the foundation library. You can find more information about the foundation library in Flutter's official documentation.

How do I get Started with flutter web support?

This page covers the following steps for getting started with web support: Configure the flutter tool for web support. Create a new project with web support. Run a new project with web support. Build an app with web support. Add web support to an existing project. To create a Flutter app with web support, you need the following software:

How do I run a Flutter App on a chrome device?

If Chrome is installed, the flutter devices command outputs a Chrome device that opens the Chrome browser with your app running, and a Web Server that provides the URL serving the app. In your IDE, you should see Chrome (web) in the device pulldown.

What do I need to debug a Flutter App?

Chrome; debugging a web app requires the Chrome browser. Optional: An IDE that supports Flutter. You can install Android Studio, IntelliJ IDEA , or Visual Studio Code and install the Flutter and Dart plugins to enable language support and tools for refactoring, running, debugging, and reloading your web app within an editor.

How do I return to another channel in flutter?

Returning to another channel (beta or master) requires calling flutter channel <channel> explicitly. If Chrome is installed, the flutter devices command outputs a Chrome device that opens the Chrome browser with your app running, and a Web Server that provides the URL serving the app. In your IDE, you should see Chrome (web) in the device pulldown.


Video Answer


1 Answers

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.

like image 59
Spatz Avatar answered Oct 14 '22 02:10

Spatz