How to specify a port number while running flutter web

爱⌒轻易说出口 提交于 2020-08-27 04:32:39

问题


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.


回答1:


I found the answer inside the flutter_tools source code:

flutter run -d headless-server --web-port=1234



回答2:


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 chome i.e.

{   
 "version": "0.2.0",
 "configurations": [{
        "name": "Flutter",
        "request": "launch",
        "type": "dart",
        "args": ["-d", "chrome","--web-port", "8000"],
    }
]}

Now run CTRL+F5




回答3:


This works well too -

flutter run -d web-server --web-port 8080


来源:https://stackoverflow.com/questions/58248277/how-to-specify-a-port-number-while-running-flutter-web

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!