Visual Studio Code

Installation and setup

Visual Studio,Follow the Set up an editor commands to put in the Dart and Flutter extensions (also known as plugins).

Updating the extension

Updates to the extensions are shipped on a everyday foundation. By default, VS Code automatically updates extensions while updates are to be had.

To install updates manually:

  1. Click at the Extensions button in the Side Bar
  2. If the Flutter extension is proven with an to be had update, click on the update button after which the reload button

Visual Studio,Creating projects

Visual Studio,Creating a new project

To create a new Flutter mission from the Flutter starter app template:

  1. Open the Command Palette (Ctrl+Shift+P (Cmd+Shift+P on macOS)).
  2. Select the Flutter: New Project command and press Enter.
  3. Enter your preferred Project name.
  4. Select a Project location.

Opening a project from existing source code

To open an existing Flutter challenge:

  1. Click File > Open from the principle IDE window.
  2. Browse to the listing conserving your existing Flutter source code documents.
  3. Click Open.

Editing code and viewing issues

The Flutter extension performs code evaluation that allows:

  • Syntax highlighting.
  • Code completions primarily based on rich type analysis.
  • Navigating to kind declarations (Go to Definition or F12), and locating kind usages (Find All References or Shift+F12).
  • Viewing all contemporary supply code problems (View > Problems or Ctrl+Shift+M (Cmd+Shift+M on macOS)). Any evaluation troubles are proven within the Problems pane:
Problems pane

Visual Studio,Running and Debugging

Start debugging through clicking Debug > Start Debugging from the main IDE window or press F5.

Visual Studio,Selecting a target device

When a Flutter project is open in VS Code, you should see a fixed of Flutter precise entries within the reputation bar, inclusive of a Flutter SDK version and a device call (or the message No Devices).

Flutter device

Note: If you do no longer see a Flutter version range or device information your undertaking won’t have been detected as a Flutter mission. Ensure the folder that includes your pubspec.Yaml is inside a VS Code Workspace Folder. If the fame bar reads No Devices Flutter has now not been able to discover any related iOS or Android gadgets or simulators. You need to attach a tool, or start a simulator or emulator, to proceed.

The Flutter extension automatically selects the remaining device connected. However, if you have multiple gadgets/simulators linked, click on device inside the status bar to look a select-list at the pinnacle of the display. Select the device you want to apply for strolling or debugging.

Visual Studio,Run app without breakpoints

  1. Click Debug > Start Without Debugging within the main IDE window, or press Ctrl+F5. The repute bar turns orange to show you’re in a debug consultation.
Debug Console

Visual Studio,Run app with breakpoints

  1. If favored, set breakpoints on your source code.
  2. Click Debug > Start Debugging within the main IDE window, or press F5.
    • The left Debug Sidebar shows stack frames and variables.
    • The backside Debug Console pane indicates precise logging output.
    • Debugging is based totally on a default release configuration. To customise, click the cog at the top of the Debug Sidebar to create a release.Json record. You can then adjust the values.

Fast edit and refresh development cycle

Flutter offers a satisfactory-in-magnificence developer cycle allowing you to look the impact of your changes almost instantly with the Stateful Hot Reload function. See Using warm reload for details.

Visual Studio,Advanced debugging

Debugging visual layout issues

During a debug consultation, several extra debugging instructions are brought to the Command Palette, together with:

  • Toggle Baseline Painting: Causes every RenderBox to color a line at each of its baselines.
  • Repaint Rainbow: Show rotating colorations on layers while repainting.
  • Toggle Slow Animations: Slow down animations to allow visible inspection.
  • Toggle Slow-Mode Banner: Hide the gradual mode banner even when running a debug construct.

Debugging external libraries

By default, debug an outside library is disabled in Flutter extension. To permit:

  1. **Settings > Extensions > Dart Configuration **
  2. Check alternative Debug External Libraries

The Flutter Inspector, performance profiling, and Dart DevTools

Dart DevTools are a fixed of debugging and profiling gear provided with an html-based UI. DevTools replaces the previous browser-based totally profiling tool, Observatory, and consists of functionality formerly handiest available to IntelliJ, just like the Flutter Inspector.

DevTools remains in development however is available to preview. For set up and getting started out commands, see the DevTools’ medical doctors.

Editing tips for Flutter code

If you have extra suggestions we should share, allow us to recognize!

Assists & Quick Fixes

Assists are code changes related to a sure code identifier. A wide variety of these are to be had while the cursor is located on a Flutter widget identifier, as indicated by using the yellow lightbulb icon. The assist can be invoked with the aid of clicking the lightbulb, or by using using the keyboard shortcut Ctrl+. (Cmd+. On Mac), as illustrated right here:

Code Assists

Quick Fixes are similar, best they are proven with a piece of code has an errors and they could assist in correcting it.

Wrap with new widget help This may be used when you have a widget which you need to wrap in a surrounding widget, as an instance if you need to wrap a widget in a Row or Column.

Wrap widget listing with new widget help Similar to the help above, but for wrapping an present listing of widgets in place of an character widget.

Convert child to kids help Changes a infant argument to a children argument, and wraps the argument value in a listing.

Snippets

Snippets may be used to hurry up getting into usual code structures. They are invoked by using typing their prefix, after which selecting from the code completion window:

Snippets

The Flutter extension consists of the subsequent snippets:

  • Prefix stless: Create a brand new subclass of StatelessWidget.
  • stful: Create a brand new subclass of StatefulWidget and it’s related State subclass.
  • Prefix stanim: Create a new subclass of StatefulWidget, and it’s associated State subclass which includes a area initialized with an AnimationController.

You also can outline custom snippets by using executing Configure User Snippets from the Command Palette.

Keyboard Shortcuts

Hot Reload

During a debug consultation, clicking the Restart button on the Debug Toolbar, or urgent Ctrl+Shift+F5 (Cmd+Shift+F5 on macOS) plays a hot reload. Keyboard mappings may be changed by executing the Open Keyboard Shortcuts command from the Command Palette.

Hot Restart

reloads vs. Hot restarts

Reload works with the aid of injecting up to date supply code documents into the strolling Dart VM (Virtual Machine). This consists of no longer simplest including new classes, however additionally including methods and fields to present training, and converting existing capabilities. A few forms of code modifications cannot be hot reloaded although:

  • Global variable initializers.
  • Static area initializers.
  • The main() method of the app.

For these modifications, completely restart your application while not having to cease your debugging consultation. To perform a warm restart, run the Flutter: Restart command from the Command Palette, or press Ctrl+F5.

Troubleshooting

Known issues and feedback

All known insects are tracked in the difficulty tracker: Dart and Flutter extensions GitHub trouble tracker.

We very tons welcome feedback, both on bugs/issues and characteristic requests. Prior to filing new issues:

  • Do a short seek in the issue trackers to peer if the problem is already tracked.
  • Make certain you’ve got up to date to the most current model of the plugin.

When submitting new problems, encompass flutter medical doctor output.