source_helper
1.4.0, released 5 weeks ago by google.dev
Utilities to help with Dart source code generation and string literal formatting.
What it does
Provides utility functions and extensions for Dart source code generation. Includes features for properly generating String literals from any value and working with analyzer elements like DartType and constructors.
AI-written summary of version 1.4.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You are building a custom Dart source code generator.
- You need to handle string escaping and literal generation safely within builders.
- You want helper methods for analyzer elements such as DartType and executable elements.
Skip it when
- You are writing a standard Flutter application without custom code generators.
- You are looking for general-purpose runtime utilities.
Strengths
- Simplifies common tasks in custom source code generation.
- Well-maintained compatibility with recent analyzer and source_gen packages.
Weaknesses
- Niche utility only applicable to developers writing code generators.
- No official support or guarantee from Google.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- Yes (build_runner)
- Direct dependencies
- 2
Add source_helper as a dependency in pubspec.yaml alongside source_gen and analyzer.
Alternatives
Packages that do the same job and could replace source_helper.
- code_builder
A fluent, builder-based library for generating valid Dart code programmatically.
93Compare - freezed
Code generation for immutable classes, tagged unions, and cloning without boilerplate.
96Compare - copy_with_extension
Annotation for generating copyWith extensions code using copy_with_extension_gen.
87Compare - flutter_gen_runner
Generates strongly-typed Dart classes for Flutter assets, fonts, and colors to avoid string-based APIs.
87Compare
Works with
Packages commonly used together with source_helper: ones it builds on, ones built on it, and its own family.
- analyzersource_helper depends on itPerforms static analysis of Dart code for tool integration and embedding.
- source_gensource_helper depends on itSource code generation builders and utilities for the Dart build system.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.
- json_serializableBuilt on source_helperAutomatically generate code for converting Dart classes to and from JSON.
- go_router_builderBuilt on source_helperA code generator for type-safe route helpers and definitions with package:go_router.
- hive_generatorBuilt on source_helperGenerates Hive TypeAdapter code for Dart classes automatically.
- theme_tailorBuilt on source_helperGenerates boilerplate for Flutter ThemeExtension classes using annotations.
- build_cliBuilt on source_helperParse command line arguments directly into an annotation class using build_runner or a standalone CLI.