Dart-code: Flutter Web: Specify Chrome port number?

Created on 1 Jun 2019  ·  5Comments  ·  Source: Dart-Code/Dart-Code

Hi
In a Flutter Web project, when I "Start Without Debugging",
a Chrome window opens on a random port

However, to do functional tests, I'd like to specify the port
Is there a config where I can specify that port number?

fixed in dart / flutter

Most helpful comment

This is now possible with Flutter's --web-port argument. You can add it in your launch.json config like this:

{
    "name": "Flutter",
    "request": "launch",
    "type": "dart",
    "args": ["--web-port", "8686"]
},

You could also set it in dart.flutterAdditionalArgs but then it would apply to the whole workspace or all apps (depending on where you set it).

Note: This only works with the unforked web support (which isn't available on the master branch).

All 5 comments

It's not currently possible to specify that port from VS Code. I think it should be easy enough to add though. In the meantime, if you start the app manually (by running webdev serve and passing a port - see https://pub.dev/packages/webdev#usage) then hopefully that'll work (you could also do this from a VS Code "task" so you can run it quickly from the IDE).

Apparently it's not easy to add, it needs support in webdev (the above arguments don't apply to daemon mode).

https://github.com/dart-lang/webdev/issues/424

This is now possible with Flutter's --web-port argument. You can add it in your launch.json config like this:

{
    "name": "Flutter",
    "request": "launch",
    "type": "dart",
    "args": ["--web-port", "8686"]
},

You could also set it in dart.flutterAdditionalArgs but then it would apply to the whole workspace or all apps (depending on where you set it).

Note: This only works with the unforked web support (which isn't available on the master branch).

@DanTup I can specify a port number when I run flutter from command line using flutter run -d chrome --web-hostname localhost --web-port 7357 but then I can't figure out how to use that port automatically from the launch.json. Here is my launch.json... does it all add up? It just launches on a random port.

{
  "version": "0.2.0",
  "configurations": [


    {
      "name": "Dart",
      "type": "dart",
      "request": "launch",
      "program": "lib/main.dart"
    },

    {
      "name": "Flutter",
      "request": "launch",
      "type": "dart",
      "args": ["--web-port", "7357"]
    }
  ]
}

@Ollynov you appear to have two launch configurations there, so unless you're selecting the second one (named Flutter) on the Run side bar, it won't be having any effect. You an merge these together into a single config that should fix this:

    {
      "name": "Flutter (port 7375)",
      "type": "dart",
      "request": "launch",
      "program": "lib/main.dart"
      "args": ["--web-port", "7357"]
    }
Was this page helpful?
0 / 5 - 0 ratings