Formatter

Dart Formatter

Format No sign in

Formatter example

Compare the exact input shape with the cleaned output before opening the editor.

Local preview

Before

input
function dart(){return true}

After

formatted
function dart() {
  return true
}

Workflow

Use Dart without sending code.

Paste a snippet, run the action, review any highlighted issue, then copy the result back to your work.

Current language
Dart
Current action
Formatter
  1. 01

    Start

    Paste a snippet or full file into the editor.

  2. 02

    Run

    Use Run Formatter from the action bar.

  3. 03

    Review

    Fix syntax issues if processing stops.

  4. 04

    Move

    Use Copy code when the result is ready.

Files
.dart
Paste a Dart snippet or a full source file.
Engine
dart format
Runs the browser-side formatter for readable output.
Privacy
Local run
The editor does not send pasted code to a formatting API.
Result
Readable output
Move the formatted code back to your editor.

Dart formatting guide

Dart formatting, explained.

Dart is unusual: the language ships with an official formatter, dart style, and the community follows it almost universally. This page runs a WebAssembly build of the same rule set, so results match dart format - in your browser, with no upload.

The rules dart format applies

The formatter uses a greedy line-splitting algorithm over the parsed tree. The visible outcomes are stable: 2-space indentation, spaces inside braces, 80-column target width, and trailing commas added wherever a construct would otherwise split.

Because formatting starts from a parse, the output is canonical: two developers formatting the same file always get identical text. That is why Dart teams simply commit the output and skip style review.

RuleValueEffect
Indentation2 spacesNever tabs.
Page width80 columnsConstructs that do not fit split onto lines.
Trailing commasAdded automaticallyForces a split for lists, maps, and argument lists.
String stylePreservedQuotes and interpolation are not rewritten.

Formatting Dart in your editor and CLI

The Dart and Flutter VS Code extensions format on save once formatOnSave is enabled - there is nothing extra to install. On the command line, dart format . rewrites every file under the current directory.

Use this page for code that lives outside a package: snippets from issues, samples from documentation, or quick checks on generated code.

  • VS Code: Dart extension, format on save, dart-style rules by default.
  • Flutter: flutter format . or dart format . from the project root.
  • CI: run dart format --output=none --set-exit-if-changed . to fail unformatted diffs.
  • This page: paste, format, copy - nothing is uploaded.

Why trailing commas matter in Dart

In Dart, a trailing comma is a formatting instruction. When a list of arguments or collection elements ends with a comma, the formatter always splits it one item per line; without the comma, it keeps items on one line when they fit.

Teams that want vertical widget trees in Flutter add the comma; teams that prefer compact calls remove it and let the width rule decide. The formatter never removes your trailing commas - it only adds them where a split already happened.