Skip to main content

Dart Code Formatter

Format and beautify Dart / Flutter source with dart_style-inspired rules — re-indent by bracket depth, normalize operator spacing, sort & group imports, and add trailing commas to multi-line lists.

Input

Drop a file or browse
One file · text
Or

Formatting Options

Output

Formatted Code
 
Was this helpful?

Guides

The Dart Code Formatter cleans up and beautifies Dart and Flutter source code in your browser. Paste messy, hand-written, or minified Dart, and it re-indents every block, normalizes operator spacing, sorts your imports, and tidies multi-line argument lists — all instantly, with nothing sent to a server. It follows the spirit of dart format (the official Dart style tool) with a fast, dependency-free set of rules.

How to use it

  1. Paste your Dart code into the input box, or upload a .dart file.
  2. Pick an indent size — 2 spaces (the Dart default), 4 spaces, or tabs.
  3. Toggle the formatting options you want: import sorting, trailing commas, and blank-line collapsing.
  4. The formatted result appears on the right, ready to copy or download as formatted.dart.

Formatting runs automatically as you type, so you can tweak options and watch the output update live.

What it does

  • Re-indents by nesting depth. Braces {}, parentheses (), and brackets [] drive the indent level, so nested classes, functions, and collections line up consistently. A Dart-aware tokenizer means brackets inside strings and comments never throw off the indentation.
  • Normalizes operator spacing. It adds tidy spaces around =, ==, =>, ??, &&, ||, compound assignments, and after commas and map colons — while leaving the contents of strings and comments completely untouched.
  • Sorts and groups directives. When enabled, import/export lines are alphabetized and split into the conventional three groups: dart: first, then package:, then relative paths, separated by blank lines.
  • Adds trailing commas. Multi-line argument, parameter, and collection lists get a trailing comma before their closing ) or ], which keeps Dart's own formatter happy and produces cleaner diffs.
  • Collapses extra blank lines and inserts a blank line between top-level declarations.

Is this the same as dart format?

It is inspired by dart format but is a lightweight, heuristic reformatter rather than a full re-implementation. It re-indents and spaces tokens reliably, but it does not wrap or reflow long lines the way the official tool does. For most everyday cleanup — pasted snippets, generated code, or fixing indentation — it produces clean, readable output. For a canonical build-pipeline format, run the official dart format locally.

Does it change my code's behavior?

No. It only adjusts whitespace, indentation, blank lines, trailing commas, and import order. It never rewrites identifiers, string contents, or logic, so the compiled result is identical.

Can I format Flutter widget trees?

Yes. Deeply nested widget constructors indent cleanly, and the trailing-comma option matches the style Flutter developers use to keep widget trees readable.

Why did import sorting move my comments?

Sorting only reorders the import/export directive lines themselves. If you rely on a specific import order, leave the "Sort and group directives" option off.

Privacy

Everything happens locally in your browser. Your Dart code is never uploaded, stored, or sent anywhere — the formatting logic runs entirely on your device, so it is safe to use with private or proprietary source.

dartfluttercode formatterbeautifyindentdart formatimports

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.