dart-best-practices
General best practices for Dart development. Covers code style, effective Dart, and language features.
Guidelines and best practices for refactoring consecutive prints, single-line string concatenations, and complex output blocks into triple-quoted multi-line string literals (''' or """) in Dart.
$ npx -y skills add kevmoo/dash_skills --skill dart-multiline-strings --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/dart-multiline-stringsContext preview
The summary Claude sees to decide when to auto-load this skill.
Guidelines and best practices for refactoring consecutive prints, single-line string concatenations, and complex output blocks into triple-quoted multi-line string literals (''' or """) in Dart.
name: dart-multiline-strings
description: |-
Guidelines and best practices for refactoring consecutive prints, single-line
string concatenations, and complex output blocks into triple-quoted multi-line
string literals (''' or """) in Dart.
license: Apache-2.0
key_features:
- Triple-quoted multiline strings
- Print & concatenation refactoring
- Formatting large text blocksUse this skill when:
single, cohesive output block.
newlines (`\n`), or use nested indentations.
templated messages) to be readable, maintainable, and performant.
Do NOT refactor to multiline strings when:
(<80 chars) without embedded newlines.
bundles (e.g. `intl`, ARB files), where line breaks or formatting must conform to external translation tooling.
strict CSV rows, or queries where indentation whitespace inside triple quotes would alter payload semantics or introduce unintended leading spaces.
console streams where individual writes occur with delays or flushing between lines.
To find candidate code blocks for multi-line string refactoring:
function, especially inside loops, console views, or CLI controllers.
string literal splits that are meant to represent multi-line outputs.
Instead of calling `print()` repeatedly for a multi-line output, group the contents into a single triple-quoted string literal: `print('''...''')`.
In a triple-quoted literal, the exact spacing and formatting inside the quotes are preserved. Use this to specify indentation levels visually instead of using manually padded space prefixes (e.g., `' '`).
If there are empty `print()` or `print('')` statements serving as vertical separators between output segments, replace them by letting the trailing newline of a multi-line string block handle the separation naturally.
If the opening triple-quote is immediately followed by a newline, the compiler discards it.
fresh line in the source code for clean layout.
line inside the triple-quoted block, or use `\n` explicitly at the beginning:
print('''
This starts with one blank line above it.''');`print()` automatically appends a trailing newline to the printed output.
blank line will be printed.
immediately after the final character:
// ✅ Emits standard output with no extra trailing empty line:
print('''
Header
Content''');When injecting optional content via interpolation (`${condition ? '...' : ''}`), placing the `${...}` on its own line leaves behind its enclosing newline when the condition evaluates to `''`, producing an empty blank line in the output.
newline only renders when the content is present:
// ✅ Clean conditional rendering without ghost blank lines:
print('''
Branch Details:
Name: $branch${hasWarning ? '\n WARNING: $warningMessage' : ''}''');The `lines_longer_than_80_chars` lint rule **automatically ignores** lines inside multiline string literals. You can write long lines inside triple-quotes without triggering linter warnings or being forced to break them up.
Leverage Dart 3 switch expressions directly inside string interpolations to dynamically select and inject optional lines, conditional labels, or helper instructions. This avoids cluttering the surrounding code with imperatively constructed strings or multiple `if` statements:
print('''
Status: ${status.isSuccess ? 'PASS' : 'FAIL'}${switch (status) {
Status.failed => '\nError details: $errorMessage',
_ => '',
}}''');**Avoid:**
void printGerritView(String branch, String desc, bool hasConflicts) {
print('Branch Details:');
print(' Name: ' + branch);
print(' Description: ' + desc);
print('');
if (hasConflicts) {
print(' WARNING: This branch has conflicts.');
print(' Run `git merge origin/main` to resolve.');
}
}**Prefer:**
void printGerritView(String branch, String desc, bool hasConflicts) {
print('''
Branch Details:
Name: $branch
Description: $desc${hasConflicts ? '''
WARNING: This branch has conflicts.
Run `git merge origin/main` to resolve.''' : ''}''');
}General best practices for Dart development. Covers code style, effective Dart, and language features.
Best practices for validating Dart documentation comments. Covers using `dart doc` to catch unresolved references and macros.
Guidelines for handling long lines in Dart code to adhere to the 80-column rule. The `lines_longer_than_80_chars` lint.
Best practices for using `expect` and `package:matcher`. Focuses on readable assertions, proper matcher selection, and avoiding…
Guidelines for using modern Dart features (v3.0 - v3.10) such as Records, Extension Types, Class Modifiers, Wildcards, Digit…
Guidelines for maintaining external Dart packages, covering versioning, publishing workflows, and pull request management. Use…