Dart Annotation Processor for reducing boilerplate code. Heavily inspired by https://projectlombok.org/
Add smartbok as a dev dependency.
dev_dependencies:
smartbok:
Run the generator
dart run build_runner build
flutter packages pub run build_runner build
// or watch
flutter packages pub run build_runner watch
Generates an extension for the annotated class, with a generated $copyWith Method.
// model.dart
@CopyWith
class Model {
final String text;
final num number;
String someText;
Model(this.text, {this.number});
}
// model.g.dart
extension ModelCopyWithExtension on Model {
Model $copyWith({String? text, num? number, String? someText}) {
final model = Model(
text ?? this.text,
number: number ?? this.number
);
model.someText = someText ?? this.someText;
return model;
}
}