Pub Package

Uses Dart Build System builders for generating boilerplate code.

So far this generator generates code when they find classes annotated with adeptannotations.

This generator creates a function that returns a new instance of the annotated ClassType by creating a copy of the currentData and replacing its fields with the newData

Notes:

  1. The function will use the values from newData, in case of null then currentData values will be used.
  2. If mergeParam is true then currentData will mirror the new instance returned.
  3. If @CloneKey(forceNewData: true) annotation is used in some field, then newData value will be forced for the specified field no matter it's nullability

Example:

import 'package:adeptannotations/adeptannotations.dart';
import 'package:newfluttertest/src/currency.dart';

part 'price.g.dart';

@Cloneable()
class Price implements ICloneable<Price>{
  num amount;
  Currency currency;
  @CloneKey(forceNewData: true) DateTime _date;

  Price({this.amount, this.currency = Currency.EUR});

@override
  Price clone({Price data, bool merge = false}) =>
    $PriceClone(currentData: this, newData: data, merge: merge);
}

After running: flutter pub run build_runner build

part of 'price.dart';

Price $PriceClone({Price currentData, Price newData, bool merge = false}) {
  final clone = Price()
    ..amount = newData?.amount ?? currentData.amount
    ..currency = newData?.currency ?? currentData.currency
    .._date = newData?._date;

  if (merge ?? false) {
    currentData.amount = clone?.amount;
    currentData.currency = clone?.currency;
    currentData._date = clone?._date;
  }

  return clone;
}

Libraries

adeptgenerator