mix_annotations 2.0.0 copy "mix_annotations: ^2.0.0" to clipboard
mix_annotations: ^2.0.0 copied to clipboard

Annotations for mix and mix_generator

mix_annotations #

Pub Version MIT Licence

Annotations used by mix_generator to generate boilerplate code for the Mix styling framework.

Installation #

flutter pub add mix_annotations

This package is typically used alongside mix and mix_generator:

dependencies:
  mix: ^2.0.0
  mix_annotations: ^2.0.0

dev_dependencies:
  build_runner: ^2.4.0
  mix_generator: ^2.0.0

Annotations #

@MixableSpec #

Generates copyWith, ==/hashCode, and lerp methods for Spec classes (immutable style data).

@MixableSpec()
final class BoxSpec extends Spec<BoxSpec> with _$BoxSpec {
  final Color? color;
  final double? width;

  const BoxSpec({this.color, this.width});
}

Control which methods are generated via GeneratedSpecMethods flags:

@MixableSpec(methods: GeneratedSpecMethods.skipLerp)

@MixableStyler #

Generates a mixin for Styler classes (mutable builders) with setter methods, merge(), resolve(), debugFillProperties(), props, and call().

@MixableStyler()
class BoxStyler extends Style<BoxSpec>
    with Diagnosticable, ..., _$BoxStylerMixin {
  final Prop<AlignmentGeometry>? $alignment;
  final Prop<Color>? $color;

  // ...
}

Control which methods are generated via GeneratedStylerMethods flags:

@MixableStyler(methods: GeneratedStylerMethods.skipCall)

@Mixable #

Generates a mixin for Mix classes (compound property types) with merge(), resolve(), props, and debugFillProperties().

@Mixable()
final class BoxConstraintsMix extends ConstraintsMix<BoxConstraints>
    with DefaultValue<BoxConstraints>, Diagnosticable, _$BoxConstraintsMixMixin {
  final Prop<double>? $minWidth;
  final Prop<double>? $maxWidth;

  // ...
}

@MixableField #

Configures code generation for individual fields in Styler classes.

// Skip setter generation for this field
@MixableField(ignoreSetter: true)
final Prop<Matrix4>? $transform;

// Override the setter parameter type
@MixableField(setterType: List<Shadow>)
final Prop<List<Shadow>>? $shadows;

Generator Flags #

Each annotation accepts bitwise flags to control which methods or components are generated:

Class Available Flags
GeneratedSpecMethods copyWith, equals, lerp
GeneratedStylerMethods setters, merge, resolve, debugFillProperties, props, call
GeneratedMixMethods merge, resolve, props, debugFillProperties

Use all (default) to generate everything, or skip* helpers to exclude specific methods:

GeneratedSpecMethods.skipLerp      // all except lerp
GeneratedStylerMethods.skipCall    // all except call
GeneratedMixMethods.skipResolve    // all except resolve

Code Generation #

After annotating your classes, run build_runner to generate code:

dart run build_runner build

Or within the Mix monorepo:

melos run gen:build

Learn More #

1
likes
140
points
28.4k
downloads

Documentation

API reference

Publisher

verified publisherleoafarias.com

Weekly Downloads

Annotations for mix and mix_generator

Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

More

Packages that depend on mix_annotations