boilerplate_generators 2.0.6 copy "boilerplate_generators: ^2.0.6" to clipboard
boilerplate_generators: ^2.0.6 copied to clipboard

Set of code generators for copyWith and copyWithNull methods with deepCopy support, Equatable props generation.

example/lib/main.dart

import 'package:boilerplate_annotations/boilerplate_annotations.dart';
import 'package:equatable/equatable.dart';

part 'main.g.dart';

@props
@copyWith
class Payment extends Equatable {
  final int id;
  final String? description;
  final Customer? customer;
  const Payment({required this.id, this.customer, this.description});

  @override
  List<Object?> get props => _$PaymentProps(this);
}

@props
@copyWith
class Customer extends Equatable {
  final int id;
  final String name;
  final String surname;
  final String? patronymic;
  final Address? address;
  const Customer({
    required this.id,
    required this.name,
    required this.surname,
    this.patronymic,
    this.address,
  });

  @override
  List<Object?> get props => _$CustomerProps(this);
}

@props
@copyWith
class Address extends Equatable {
  final String? street;
  final int? home;
  const Address({this.street, this.home});

  @override
  List<Object?> get props => _$AddressProps(this);
}

void main(List<String> arguments) {
  const payment = Payment(
    id: 4,
    description: 'test',
    customer: Customer(id: 1, name: 'John', surname: 'Dou', patronymic: 'test'),
  );

  payment.copyWith(
    description: null,
  ); // == Payment(id: 4,description: 'test',customer:Customer(id: 1, name: 'John', surname: 'Dou', patronymic: 'test'),),),);
}
1
likes
150
points
60
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Set of code generators for copyWith and copyWithNull methods with deepCopy support, Equatable props generation.

Repository (GitHub)
View/report issues

Topics

#codegen #copy-with

License

BSD-3-Clause (license)

Dependencies

analyzer, boilerplate_annotations, build, source_gen

More

Packages that depend on boilerplate_generators