Reputation: 1263
I have flutter web app which can be easily deploy to chrome browser on my PC. Upon successful deployment:
I'm looking for the way to access localhost running in chrome from my iPhone browser. My iPhone and PC both connected to the same network. I grabbed IP address of the network and tried accessing from my iPhone safari browser with the link as:
But it's NOT working and I'm getting 'The site can't be reached' message. Is there any extra step I can perform to make flutter localhost accessible from my mobile browser or simply its impossible with flutter ?
Upvotes: 26
Views: 32326
Reputation: 106
To access on another machines which are connected to same network
flutter run -d web-server --web-port (port) --web-hostname (your-ip-address)
Example:
flutter run -d web-server --web-port 8080 --web-hostname 192.168.100.17
so then we you hit the link http://192.168.100.17:8080 it will open the app
Upvotes: 2
Reputation: 1572
The only way I managed to make it work on the Mac and test on the iPhone:
In your terminal, inside the project folder:
flutter build web
Building without sound null safety For more information see https://dart.dev/null-safety/unsound-null-safety
Compiling lib/main.dart for the Web... 34.5s
cd build/web
python3 -m http.server 8000
Serving HTTP on :: port 8000 (http://[::]:8000/) ... ::1 - - [28/Mar/2021 18:34:31] "GET / HTTP/1.1" 200 - ::1 - - [28/Mar/2021 18:34:31] "GET /main.dart.js HTTP/1.1" 200 - ::1 - - [28/Mar/2021 18:34:31] "GET /manifes....
Then in a new terminal tab:
~/ngrok http 8000
Forwarding https://xxxxxx.ngrok.io
or information on how to use ngrok: www.ngrok.com
Upvotes: 8
Reputation: 800
If you want debug only, you may use
flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0
then access http://<your-ip>:8080
** also you should ensure that your port(8080) is open.
Upvotes: 80
Reputation: 647
Alternative
flutter build web
cd <pathProject>/web/build
python -m http.server 5000
ngrok http.server 5000
Upvotes: 3
Reputation: 899
Use this free service ngrok.com that lets you expose your localhost publicly. So you can not only access your app while developing from the same network but also share it with some one else over the internet, in your case your mobile.
Upvotes: 1
Reputation: 33511
While you're developing your app, Flutter doesn't really output the JS. The flutter run
command launches the application using the development compiler in a Chrome browser, which means that Dart code runs directly in Chrome. And you cannot really access Chrome from another machine in the network, as it doesn't act as a server.
You should probably compile your app in JS (AKA flutter build web
) for a regular deployment, to access it from other hosts. You could use Python's simple HTTP server to serve the app. There is no need to install any frameworks, configure anything, and writte Python code. Just make sure you have Python 3 installed and run python -m http.server 8000
from your apps build output. It will serve the app on port 8000.
Upvotes: 10