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?
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.
Flutter web apps can run on the following browsers: Chrome (mobile & desktop) Safari (mobile & desktop) Edge (mobile & desktop)
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.
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:
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With