Skip to content
pubscout

source_span

1.10.2, released 9 months ago by tools.dart.dev

Standard representation for source code locations, spans, and human-friendly error messages.

WASM-ready
$ flutter pub add source_span
Source repository

What it does

Provides classes like SourceSpan and SourceFile to track positions in source code files. It allows packages to easily pass code locations around and generate clear, human-friendly error messages with line and column highlights.

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

Use it when

  • You are writing a parser, compiler, linter, or code generator that needs to report source code errors.
  • You want to standardize source location tracking across multiple custom packages.

Skip it when

  • You are building a standard mobile application UI without any code parsing requirements.

Strengths

  • Generates clean, human-friendly error messages with file context and line numbers.
  • Efficient means of computing line and column numbers using SourceFile.
  • Supports multi-span highlights and Unicode box-drawing characters.

Weaknesses

  • Very niche utility package with no application outside of parsing and tooling.

Setup

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

void main() {
  var file = SourceFile.fromString('some code here', url: 'main.dart');
  var span = file.span(0, 4);
  print(span.message('Here is an error'));
}

Alternatives

Packages that do the same job and could replace source_span.

  • io

    Utilities for the Dart VM Runtime including ANSI colors, file copying, and exit code values.

  • hotreloader

    Automatic hot code reloader for Dart projects that applies file changes to the running process.

  • flutter_patcher

    Self-hosted OTA hotfix tool for Flutter with signed code and asset patches.

  • qris

    Parses Indonesian QRIS codes into merchant and transaction data.

Works with

Packages commonly used together with source_span: ones it builds on, ones built on it, and its own family.