PyCharm 5.0 Help

Running and Debugging Dart Command-Line Applications

Dart is intended for developing Web and command-line applications. PyCharm supports both workflows.

  • For running and debugging Dart command-line applications, PyCharm provides a dedicated run/debug configuration of the type Dart Command Line Application.
  • To run and debug a Dart Web application in a browser, you either need to use the Dartium browser or have the Dart code translated into JavaScript.

    Most browsers that work with JavaScript code do not natively process Dart code. The only exception is Dartium. This dart-oriented version of Chromium contains a built-in Dart VM and therefore can run Dart code directly. To be executed in any other browser, Dart code has to be compiled into JavaScript.

    With the pub tool, the compilation is performed through the pub serve action using the built-in dart2js compiler.

    In PyCharm, transpiler configurations are called File Watchers. For each supported transpiler, PyCharm provides a predefined File Watcher template. Predefined File Watcher templates are available at the PyCharm level. To run a transpiler against your project files, you need to create a project-specific File Watcher based on the relevant template, at least, specify the path to the transpiler to use on your machine.

    You can run Dart Web application in any browser, while debugging is supported only in Dartium and Chrome. To run a Dart Web application you just need to open the starling HTML page in the browser of your choice. Debugging a Dart Web application is initiated through a rung configuration of the type JavaScript Debug.

On this page:

Running a Dart Command-Line Application

  1. Create a run configuration:
    1. On the main menu, choose Run | Edit Configurations.
    2. Click the Add New Configuration toolbar button add.png, and choose Dart Command Line Application on the context menu.
    3. In the Run/Debug Configuration: Dart Command Line Application dialog box that opens, specify the Dart file to start the application from. The file must contain a main() method. Optionally specify the options to launch the Dart Virtual Machine with and the program options to start the application with.
    4. Click OK to save the configuration settings.
  2. Choose the newly created configuration in the Select run/debug configuration drop-down list on the tool bar and click the Run toolbar button run.
  3. View the results in the Console tab of the Run tool window.

Debugging a Dart Command-Line Application

With PyCharm, you can debug Dart command-line applications in two modes:

  • Local debugging. In this mode, you launch the application to debug and start a debugging session through one same run configuration.
  • Remote debugging. In this mode, you initiate a debugging session and connect to an already running application. This application can be launched on another host machine or you can previously start it on your machine through another run configuration.

To debug a Dart command-line application locally:

  1. Configure and set breakpoints in the Dart code.
  2. Create a run configuration:
    1. On the main menu, choose Run | Edit Configurations.
    2. Click the Add New Configuration toolbar button add.png, and choose Dart Command Line Application on the context menu.
    3. In the Run/Debug Configuration: Dart Command Line Application dialog box that opens, specify the Dart file to start the application from. The file must contain a main() method. Optionally specify the options to launch the Dart Virtual Machine with and the program options to start the application with.
    4. Click OK to save the configuration settings.
  3. Choose the newly created configuration in the Select run/debug configuration drop-down list on the tool bar and click the Debug toolbar button debug.
  4. In the Debug Tool Window that opens, step through the program, stop and resume program execution, examine it when suspended, etc.

To debug a Dart command-line application remotely:

  1. Create a Dart Remote Debug run configuration:
    1. On the main menu, choose Run | Edit Configurations.
    2. Click the Add New Configuration toolbar button add.png, and choose Dart Command Line Application on the context menu.
    3. In the Run/Debug Configuration: Dart Remote Debug dialog box that opens, specify the host where the Dart application is running and the port for the debugger to communicate with this host. The specified port is shown in the Command line arguments for the remote Dart VM read-only field. Note that the application must be started exactly with these arguments, so do not forget to provide this information to the one who will start it on the remote host or specify the arguments in the Dart Remote Debug run configuration if you are going to launch the application yourself on the localhost.
    4. From the Search Sources in drop-down list, choose the Dart project to debug if your PyCharm project contains several Dart projects configured as content roots.
    5. Click OK to save the configuration settings.
  2. Make sure the command-line application to debug is running with the arguments from the Command line arguments for the remote Dart VM read-only field in the Dart Remote Debug run configuration.
  3. Choose the newly created Dart Remote Debug configuration in the Select run/debug configuration drop-down list on the tool bar and click the Debug toolbar button debug.
  4. In the Debug Tool Window that opens, step through the program, stop and resume program execution, examine it when suspended, etc.

See Also

Last modified: 10 December 2015