built_collection
6.0.0, released 4 weeks ago by dart.dev
Immutable collections based on SDK collections with builder pattern.
Flutter FavoriteWASM-ready
What it does
Provides immutable collection classes (like BuiltList, BuiltMap, BuiltSet) and corresponding mutable builder classes. Uses copy-on-write to avoid unnecessary copying and supports deep comparison and hashing.
AI-written summary of version 6.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need safe, immutable collections to share across your app without defensive copying.
- You want deep comparison and hashing support for collections.
- You use built_value and need matching immutable collections.
Skip it when
- You need direct mutability on standard SDK collection interfaces (built collections do not implement standard List/Set interfaces).
- You want a fully codegen-free state model where native collections or other packages suffice.
Strengths
- Enforces immutability and prevents accidental state mutations.
- Provides deep equality and caching for efficient comparisons and hashing.
- Uses copy-on-write wrappers to avoid unnecessary data copying.
Weaknesses
- Collections do not implement core SDK mutable interfaces (e.g., BuiltList does not implement List).
- Requires converting to/from builders or views when interoperating with standard SDK code.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
BuiltList([1, 2, 3]) == BuiltList([1, 2, 3]);Alternatives
Packages that do the same job and could replace built_collection.
- fast_immutable_collections
Fast immutable lists, sets, maps, and multimaps for Dart
91Compare
Works with
Packages commonly used together with built_collection: ones it builds on, ones built on it, and its own family.
- built_valueBuilt on built_collectionImmutable value types with builders, enum classes and JSON serialization for Dart.
- code_builderBuilt on built_collectionA fluent, builder-based library for generating valid Dart code programmatically.
- build_runnerBuilt on built_collectionA build system for Dart code generation and modular compilation.
- build_daemonBuilt on built_collectionDaemon for running Dart builds in the background
- retrofit_generatorBuilt on built_collectionGenerates Dio client code from Retrofit‑style annotations.
- built_value_generatorBuilt on built_collectionGenerates immutable value types, enum classes, and JSON serializers for Dart.
- gql_code_builderBuilt on built_collectionDart code builder generating typed classes from GraphQL documents and SDL
- build_testBuilt on built_collectionUtilities for unit testing Dart build_runner builders in memory