Skip to content
pubscout

copy_with_extension

18.0.1, released 5 days ago by alexander-kirsch.com

Annotation for generating copyWith extensions code using copy_with_extension_gen.

WASM-ready
$ flutter pub add copy_with_extension
Source repository

What it does

Defines annotations that work with copy_with_extension_gen to automatically generate copyWith extension methods for Dart classes and record typedefs, helping to maintain immutability.

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

Use it when

  • You want to generate copyWith methods for immutable classes without writing them manually
  • You need shallow copyWith support for annotated record typedefs

Skip it when

  • You prefer manual implementation of copyWith methods
  • You are already using a comprehensive code generation solution like freezed that includes copyWith out of the box

Strengths

  • Automates boilerplate generation for immutable models
  • Supports Dart primary constructors and shallow copying for record typedefs

Weaknesses

  • Requires build_runner and a separate generator package to produce code
  • Breaking changes in generator rules can require updating generated files and class configurations

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
1

Requires adding the package and its generator counterpart, then running build_runner.

not documented

Alternatives

Packages that do the same job and could replace copy_with_extension.

  • freezed

    Provides a comprehensive solution for union types, pattern matching, and built-in copyWith generation without needing separate manual models.

  • built_value

    Offers immutable value types with custom serialization and builders as an alternative to standard data classes.

Works with

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