Skip to content
pubscout

indent

2.0.0, released 6 years ago by iiro.dev

Provides methods to change indentation of multiline Dart strings while preserving relative indentation.

WASM-ready
$ flutter pub add indent
Source repository

What it does

The package adds extension methods to String for unindenting, trimming margins, indenting to a specific level, adjusting indentation by a delta, and retrieving the common indentation level. It works purely on string content without external dependencies.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to format multiline string literals for readability or output formatting
  • You want Kotlin‑like trimIndent/trimMargin behavior in Dart

Skip it when

  • Performance‑critical code where string manipulation overhead matters
  • You require rich text layout rather than simple whitespace adjustments

Strengths

  • Zero dependencies and pure Dart implementation
  • Simple API via String extensions
  • Handles relative indentation correctly

Weaknesses

  • Limited to whitespace indentation; no support for tabs vs spaces mixing
  • No streaming or lazy processing for very large strings

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
import 'package:indent/indent.dart';

void main() {
  const text = '''
          Hello
        there
             World!
''' ;
  print(text.unindent());
}

Alternatives

Packages that do the same job and could replace indent.

  • validators2

    String validation and sanitization for Dart.

  • any_date

    Parse strings in any format or language into DateTime objects, respecting ISO and RFC standards.

  • string_to_color

    Convert strings to colors, hex strings, or hex integers in Dart and Flutter.

  • multiline

    Provides convenient access to multiline String records with method extensions.