easy_copy_with 2.0.0 copy "easy_copy_with: ^2.0.0" to clipboard
easy_copy_with: ^2.0.0 copied to clipboard

Package for automatic generation of copyWith methods in Dart classes using @CopyWith annotation.

example/example.dart

import 'package:easy_copy_with/easy_copy_with.dart';

part 'example.g.dart';

void main() {
  const user = User(name: 'Alice', age: 25, email: 'alice@example.com');

  final older = user.copyWith(age: 26);
  final renamed = older.copyWith(name: 'Alicia');
  final withoutEmail = renamed.copyWith(email: null);

  print(user);
  print(older);
  print(renamed);
  print(withoutEmail);
}

@CopyWith()
class User {
  final String name;
  final int age;
  final String? email;
  final bool isActive;

  const User({
    required this.name,
    required this.age,
    this.email,
    this.isActive = true,
  });

  @override
  String toString() =>
      'User(name: $name, age: $age, email: $email, isActive: $isActive)';
}
2
likes
150
points
201
downloads

Publisher

unverified uploader

Weekly Downloads

Package for automatic generation of copyWith methods in Dart classes using @CopyWith annotation.

Repository (GitHub)
View/report issues

Topics

#codegen #copy-with #code-generation #annotation

Documentation

API reference

License

MIT (license)

Dependencies

analyzer, build, meta, source_gen

More

Packages that depend on easy_copy_with