Is there any way to start Flutter web, with a Headless-Server target, always on the same specified port number ?
Today, running the web application with:
flutter run -d headless-server
Provides a random port number.
Is there any way to start Flutter web, with a Headless-Server target, always on the same specified port number ?
Today, running the web application with:
flutter run -d headless-server
Provides a random port number.
I found the answer inside the flutter_tools source code:
flutter run -d headless-server --web-port=1234
flutter run -d chrome --web-port=1234
–
Furiya To do this for Android Studio, just add the additional parameters to menu Run
> Edit configuration
. So in the Additional arguments
, add --web-port=49430
Edit Configurations
–
Panlogism The above solution works fine if you are like using command line. But if you you are using VsCode by CTRL+F5
that won't work. So to make vscode CTRL+F5
run in chrome or web-server go to your project root directory create .vscode
directory and inside that folder add launch.json
file.
Now if you want to run in web server add this lines in you launch.json
{
"version": "0.2.0",
"configurations": [{
"name": "Flutter",
"request": "launch",
"type": "dart",
"args": ["-d", "web-server","--web-port", "8000"],
}
]}
And if you want to launch in chrome device change argument web-server
to chrome
i.e.
{
"version": "0.2.0",
"configurations": [{
"name": "Flutter",
"request": "launch",
"type": "dart",
"args": ["-d", "chrome","--web-port", "8000"],
}
]}
Now you can run CTRL+F5
.
"program": "lib/main.dart",
–
Monitorial launch.json
file? I tried to create launch.json
file beside pubspec.yaml
but didn't work! –
Zeal I found the answer inside the flutter_tools source code:
flutter run -d headless-server --web-port=1234
flutter run -d chrome --web-port=1234
–
Furiya You can run flutter web on any chromium based browser
Chrome | Edge
Use any one to launch flutter web application with custom port
flutter run -d chrome --web-port 5555
flutter run -d edge --web-port 5555
flutter run -d web-server --web-port 5555
EDIT
UNRELATED TO THE MAIN Question, but Helpful if you face the below-mentioned issue.
Recently faced an issue with a flutter web application, it was not running and no logs/ errors were visible.
How I fixed it.
Run flutter build web
this should print out the errors, fix those errors and then try running your application by above mentioned commands
flutter -v run -d web --web-port=28080
Still, --web-port is the trick here. :) –
Reddish Solution for VS Code
Dart: Flutter Run Additional Args
--web-port=1234
Add Item
This works well too -
flutter run -d web-server --web-port 8080
© 2022 - 2024 — McMap. All rights reserved.