mix_annotations 2.1.1 copy "mix_annotations: ^2.1.1" to clipboard
mix_annotations: ^2.1.1 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 a self-contained _$<Name> mixin for Spec classes (immutable style data). The mixin declares implements Spec<T>, Diagnosticable and inlines type, copyWith, lerp, generated props by default, ==, hashCode, toString, toDiagnosticsNode, and debugFillProperties — so the user class needs a single with to be a fully-formed Spec.

import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:mix/mix.dart';
import 'package:mix_annotations/mix_annotations.dart';

part 'box_spec.g.dart';

@MixableSpec()
@immutable
final class BoxSpec with _$BoxSpec {
  @override
  final Color? color;
  @override
  final double? width;

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

The generated mixin _$BoxSpec is the only thing the user class mixes in — Equatable-style equality (via propsEquals / propsHash helpers) and Diagnosticable's concrete surface are inlined by the generator, not pushed onto the user.

Control which methods are generated via GeneratedSpecMethods flags:

@MixableSpec(methods: GeneratedSpecMethods.skipLerp)

GeneratedSpecMethods.skipEquals suppresses generated props so the class can author custom equality inputs while still using the generated equality surface.

@MixableStyler legacy marker #

Retained for compatibility with older code and shared generated styler method flags. New Mix stylers are generated from @MixableSpec(target: Widget.new).

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

  // ...
}

GeneratedStylerMethods flags remain available for generator internals and compatibility.

@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
GeneratedMixMethods merge, resolve, props, debugFillProperties

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

GeneratedSpecMethods.skipLerp      // all except lerp
GeneratedSpecMethods.skipEquals    // user authors props; equality surface still emits
GeneratedMixMethods.skipResolve    // all except resolve

GeneratedStylerMethods.call / skipCall are retained for source compatibility, but call generation is no longer supported.

Code Generation #

After annotating your classes, run build_runner to generate code:

dart run build_runner build --delete-conflicting-outputs

Or within the Mix monorepo:

melos run gen:build

Learn More #

1
likes
150
points
20.3k
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