MCPInstall

dart-multiline-strings

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.

Installs
111
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/kevmoo/dash_skills --skill dart-multiline-strings
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads dart-multiline-strings automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Dart Multi-line Strings

1. When to use this skill

Use this skill when:

  • Refactoring consecutive print() or stdout.writeln() statements into a single, cohesive output block.
  • Simplifying string literals that span multiple lines, contain embedded newlines (\n), or use nested indentations.
  • Formatting large user-facing text output (like CLI help menus, reports, or templated messages) to be readable, maintainable, and performant.

When NOT to use (Abstention Guardrails)

Do NOT refactor to multiline strings when:

  • Short, Single-Line Outputs: Strings that comfortably fit on a single line (<80 chars) without embedded newlines.
  • Localized String Catalogs: Strings that are looked up from localization bundles (e.g. intl, ARB files), where line breaks or formatting must conform to external translation tooling.
  • Raw Query Strings with Strict Whitespace Semantics: Protocol strings, strict CSV rows, or queries where indentation whitespace inside triple quotes would alter payload semantics or introduce unintended leading spaces.
  • Streaming or Incremental I/O: Progress bars, spinners, or interactive console streams where individual writes occur with delays or flushing between lines.

Discovery

To find candidate code blocks for multi-line string refactoring:

  • Look for multiple back-to-back print() or stdout.writeln() calls inside a function, especially inside loops, console views, or CLI controllers.
  • Look for single-line strings heavily loaded with \n escape sequences.
  • Look for multiple string concatenations using the + operator or adjacent string literal splits that are meant to represent multi-line outputs.

2. Guidelines

Combine Consecutive Outputs

Instead of calling print() repeatedly for a multi-line output, group the contents into a single triple-quoted string literal: print('''...''').

Explicit and Clean Alignment

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., ' ').

Remove Empty Print Calls

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.

Handling the First Newline

If the opening triple-quote is immediately followed by a newline, the compiler discards it.

  • If you do not want a leading blank line, start the string content on a fresh line in the source code for clean layout.
  • If you do want a leading blank line in the output, leave an extra empty line inside the triple-quoted block, or use \n explicitly at the beginning:
    print('''
    
    This starts with one blank line above it.''');
    

Handling the Trailing Newline & print()

print() automatically appends a trailing newline to the printed output.

  • If you place the closing ''' on a new line (\n''');), an extra trailing blank line will be printed.
  • To avoid unintended trailing blank lines, place the closing triple-quotes immediately after the final character:
    // ✅ Emits standard output with no extra trailing empty line:
    print('''
    Header
    Content''');
    

Avoiding Ghost Blank Lines in Conditional Interpolations

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.

  • Include the leading newline inside the conditional string literal so the newline only renders when the content is present:
    // ✅ Clean conditional rendering without ghost blank lines:
    print('''
    Branch Details:
        Name: $branch${hasWarning ? '\n    WARNING: $warningMessage' : ''}''');
    

80-Character Line Limit Exemption

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.

Dynamic Switch Expressions inside Interpolation

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',
  _ => '',
}}''');

3. Examples

Refactoring Consecutive Prints with Indentation

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.''' : ''}''');
}

FAQ

What does the dart-multiline-strings skill do?

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.

How do I install dart-multiline-strings?

Run npx skills add https://github.com/kevmoo/dash_skills --skill dart-multiline-strings in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/dart-multiline-strings/ (personal) or .claude/skills/dart-multiline-strings/ (project).

Which AI agents can use dart-multiline-strings?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is dart-multiline-strings safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains dart-multiline-strings?

It is published by kevmoo in kevmoo/dash_skills. It has 111 recorded installs.

More from kevmoo/dash_skills

View all →

dart-best-practices

kevmoo/dash_skills

General best practices for Dart development. Covers code style, effective Dart, and language features.

dart-test-fundamentals

kevmoo/dash_skills

Core concepts and best practices for package:test. Covers test, group, lifecycle methods (setUp, tearDown), and configuration (darttest.yaml).

Testing & QA450 installs

dart-modern-features

kevmoo/dash_skills

Guidelines for using modern Dart features (v3.0 - v3.10) such as Records, Extension Types, Class Modifiers, Wildcards, Digit Separators, Null-Aware Elements, and Dot Shorthands.

362 installs

dart-doc-validation

kevmoo/dash_skills

Best practices for validating Dart documentation comments. Covers using dart doc to catch unresolved references and macros.

dart-package-maintenance

kevmoo/dash_skills

Open the skill to read its SKILL.md instructions.

280 installs

dart-matcher-best-practices

kevmoo/dash_skills

Best practices for using expect and package:matcher. Focuses on readable assertions, proper matcher selection, and avoiding common pitfalls.

Popular code quality & workflow skills

View category →

grill-me

mattpocock/skills

A relentless interview to sharpen a plan or design.

Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

handoff

mattpocock/skills

Compact the current conversation into a handoff document for another agent to pick up.

domain-modeling

mattpocock/skills

Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.

codebase-design

mattpocock/skills

Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.

diagnosing-bugs

mattpocock/skills

Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.