Zam Core Library

Core library for all the packages built by zamstation.

What's inside the package

Check out all the components in detail here

How to use

ParameterizedBuilder

final ParameterizedBuilder<Type, Car> carBuilder;
// ...
final car = carBuilder(HondaCivic);

ParameterizedCallback

final ParameterizedCallback<double, int> roundOffStrategy;
// ...
final price = roundOffStrategy(8.458);

NamedException

Wrapper around the built-in Exception class.

Provides more classified details of the exception like severity and solution.

Construct it with a simple problem statement.

final exception = NamedException.create('Provided value is -26 which is negative.');

or build it with more details.

final exception = NamedException.create(
  'Provided value is -26 which is negative.'
  solution: 'Please provide a positive value.'
  severity: ExceptionSeverity.critical,
);

Cloneable

@immutable
class Triangle implements Cloneable<Triangle> {
  final double base;
  final double height;

  const Triangle(this.base, this.height);

  @override
  Triangle clone() {
    return Triangle(this.base, this.height);
  }
}

Model

@immutable
class BmiModel extends Model {
  final double weight;
  final double height;
  final double value;

  @override
  get props => [weight, height];

  const BmiModel(this.weight, this.height) : value = weight / (height * height);
}

ViewModel

@immutable
class HeightViewModel extends ViewModel {
  final double value;

  @override
  get props => [value];

  const HeightViewModel(this.value);
}

Entity

@immutable
class BmiEntity extends Entity<BmiModel> {
  final String key = '';
  final double weight;
  final double height;

  @override
  get props => [weight, height];

  const BmiEntity({
    required this.weight,
    required this.height,
  });

  BmiEntity.fromJson(Json json)
      : this(
          weight: json['weight'] as double,
          height: json['height'] as double,
        );

  BmiEntity.fromModel(BmiModel model)
      : this(
          weight: model.weight,
          height: model.height,
        );

  @override
  Json toJson() {
    return {
      'key': this.key,
      'weight': this.weight,
      'height': this.height,
    };
  }

  @override
  BmiModel toModel() {
    return BmiModel(this.weight, this.height);
  }
}

To learn more, move on to the example section or check out these dedicated examples in github.

Status

Build

Contributors

License

BSD 3-Clause License