copy_with_e_generator 1.0.6 copy "copy_with_e_generator: ^1.0.6" to clipboard
copy_with_e_generator: ^1.0.6 copied to clipboard

outdated

Creates copyWith extension methods for each annotated class and works with abstract too.

###copy_with_e

For more examples look at the github repository

Simple, just put the CopyWithE annotation on the class

var bob = Person(age: 5, name: "bob");
var result = bob.cwPerson(age: 6, name: "bobby");

@CopyWithE()
class Person {
  final int age;
  final String name;

  Person({this.age, this.name});

  String toString() => "${age.toString()}, ${name.toString()}";
}

It works on superclasses automatically

var bob = Person(age: 5, name: "bob");
var rob = Employee(age: 9, name: "rob");
var hasAges = <HasAge>[bob, rob];
var result = hasAges.map((x) => x.cwHasAge(age: 3).age).toList();

@CopyWithE([Person, Employee])
abstract class HasAge {
  int get age;
}

class Person implements HasAge {
  final int age;
  final String name;

  Person({this.age, this.name});
}

One concrete class has two interfaces both of which have copyWith extension methods. It works! and that is why we name our copyWith cw[ClassName]

var ages = hasAges.map((x) => x.cwHasAge(age: 3).age).toList();

@CopyWithE([Person, Employee])
abstract class HasAge {
  int get age;
}

@CopyWithE([Person, Employee])
abstract class HasName {
  String get name;
}

class Person implements HasAge, HasName {
  final int age;
  final String name;

  Person({this.age, this.name});
}

class Employee implements Person {
  final int age;
  final String name;

  Employee({this.age, this.name});
}

Automatically gets subtypes if they exist in the same file also, it gets from the types parameter

    var bob = Person(age: 5, name: "bob");
    var rob = Employee(age: 9, name: "rob");
    var hasAges = <HasAge2>[bob, rob];
    var result = hasAges.map((x) => x.cwHasAge2(age: 3).age).toList();

@CopyWithE([Stuff, Employee]) //[Person, Employee])
abstract class HasAge2 {
  int get age;
}

class Person implements HasAge2 {
  final int age;
  final String name;

  Person({this.age, this.name});
}

class Employee implements Person {
  final int age;
  final String name;

  Employee({this.age, this.name});
}

For more examples look at the Examples project in the github repository

1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Creates copyWith extension methods for each annotated class and works with abstract too.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

analyzer, analyzer_models, basic_utils, build, copy_with_e_annotation, dartx, source_gen, tuple

More

Packages that depend on copy_with_e_generator