I am building a flutter web app, but I want it to behave differently on mobile and desktop. To test it, is it possible to run the web app on a phone's browser or in the browser of an emulator? Thanks
7 Answers
Yes, testing your code in a web browser while in production is possible. Here are steps to do that:
- Connect your devices (your laptop and phone) to the same internet
- Run the following code in the terminal of the opened project
t
flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0
Then, head to your mobile phone browser and type
HTTP://<your PC IP address>:8080
2 Comments
You need to start your flutter web-app on a specific port
flutter run -d web-server --web-port 5011Connect your device and verify if the device is connected properly
adb devicesadb port-forwarding
adb reverse tcp:5011 tcp:5011Open Mobile Browser with
http://localhost:5011/
after that, you can able to access that port on a mobile browser.
5 Comments
after that, you can able to access that port on a mobile broswer. Is it by copying the url an replacing localhost with device Ip or just copying the url like localhost:5011/# and doing something with it? Thanks.The above answer is incorrect. I test all my flutter web development in the mobile browser in the Simulator. I use VS Code. Your environment may be different.
- Run the project for Chrome (web). This launches the local server and a Chrome Browser. Copy the URL from the browser. In my case, I have it to always be http://localhost:8686/#/
- Launch the Simulator.
- Launch Safari or any other browser on the Simulator. Paste the URL in the browser.
You can even access the project from a real phone if it is on the same local network as your development machine. Just replace localhost with the IP Address of your development machine.
1 Comment
I working on a Macbook, and none of the answer from above help, but I found a pretty simple solution to test my webpage.
- The 1th you have to do is build your project with this command: flutter build web
- After that, get in the build/web folder and run this command: python3 -m http.server 8000 (For this you will need python 3.)
And that is, now you can see your webpage on both platform. On mobile you only your hosted platform's IP address. On mac, you can get with this command: ipconfig getifaddr en0
So, on your phone you can the webpage with this: your IP address:8000 Example.: 192.10.42.14:8000.
On your hosted platform it will be: 0.0.0.0:8000 (but this is only gonna work on your hosted platform)
I know, this is just a workaround, but for my situation it was very helpful.:)
Yes, you can . But instead of running a local web server and all, just run your code on your system on chrome(web)
- After your app runs on web click on inspect
- In inspect toolbar beside elements you will find a button "toggle device toolbar" click on that and you are good to go.
- Your desktop screen would give you a mobile view, you can try different devices and dimensions as well
Comments
1 - Check your computer ip using ipconfig command in your terminal.
2 - Make sure your mobile is connected to the same network (ex: your home router).
3 - Run this command in the terminal ( The IP below must be the one you got from the ipconfig command, in this case i am using this ip as an example your ip could be different).
flutter run -d web-server --web-hostname 192.168.1.24 --web-port 8080
- You can now access the server on your mobile device by opening your browser and navigating to http://192.168.1.24:8080.
Comments
Connect your device to the same internet (With Lan or Wifi or Hotspot)
Run this Command in Terminal
-
flutter run -d web-server --web-port 8080 --web-hostname 0.0.0.0 After running the command , copy your systems's IP Address
Then open provided link in app browser of that device where you want to run.
-
http://YOUR-IP-ADDRESS/8080


