I have flutter web app which can be easily deploy to chrome browser on my PC. Upon successful deployment:
- Web browser(Chrome)
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 ?
Solution 1: madhead
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.
Solution 2: unbalanced_equation
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.
Solution 3: Cristian Q
- build app :
flutter build web
- change dir :
- up any server :
python -m http.server 5000
- up ngrok :
ngrok http.server 5000
- in mobile browser : "https://a824ccb9d545.ngrok.io " (example)
Solution 4: LemonTea
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.
Solution 5: luisdemarchi
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
or information on how to use ngrok: www.ngrok.com