Skip to content

nkming2/dart-copy-with

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

copy-with

Generate copyWith() for classes

Usage

@genCopyWith
class MyClass {
  const MyClass({
    required this.a,
    required this.b,
  });

  final int a;
  final int b;
}
// MyClass().copyWith(a: 1)

Derived class is supported:

class Base {
  const Base({
    required this.a,
  });

  final int a;
}

@genCopyWith
class Derived {
  const Derived({
    required this.b,
  });

  final int b;
}
// Derived().copyWith(a: 1)

If polymorphism is needed,

@genCopyWith
class Base {
  const Base({
    required this.a,
  });

  $BaseCopyWithWorker get copyWith => _$copyWith;

  final int a;
}

@CopyWith(parent: "Base")
class Derived {
  const Derived({
    required this.b,
  });

  @override
  $BaseCopyWithWorker get copyWith => _$copyWith;

  final int b;
}
// final obj = Base().copyWith(a: 1); // type of obj is Derived

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages