adeptgenerator 1.0.0+1

Dart native

A new Flutter package.

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;
}
0
likes
60
pub points
2%
popularity

A new Flutter package.

Homepage

Documentation

API reference

Uploader

luis901101@gmail.com

License

unknown (LICENSE)

Dependencies

adeptannotations, analyzer, build, source_gen

More

Packages that depend on adeptgenerator