Code generator for the Mix styling framework. Processes mix_annotations to generate boilerplate code for Spec, Styler, and Mix classes.
flutter pub add mix
flutter pub add mix_annotations
flutter pub add --dev mix_generator
flutter pub add --dev build_runnerOr in pubspec.yaml:
dependencies:
mix: ^2.0.0
mix_annotations: ^2.0.0
dev_dependencies:
build_runner: ^2.4.0
mix_generator: ^2.0.0Generates a _$<Name> mixin for immutable Spec classes with:
copyWith()— create modified copies==/hashCode— value equalitylerp()— smooth interpolation between specs
import 'package:mix/mix.dart';
import 'package:mix_annotations/mix_annotations.dart';
part 'box_spec.g.dart';
@MixableSpec()
final class BoxSpec extends Spec<BoxSpec> with _$BoxSpec {
final Color? color;
final double? width;
final double? height;
final AlignmentGeometry? alignment;
const BoxSpec({this.color, this.width, this.height, this.alignment});
}Generates a _$<Name>Mixin for mutable Styler classes with:
- Setter methods for each
$-prefixed field merge()— combine stylesresolve()— resolve to the corresponding SpecdebugFillProperties()— diagnostics supportprops— equality comparisoncall()— widget creation
part 'box_styler.g.dart';
@MixableStyler()
class BoxStyler extends Style<BoxSpec>
with Diagnosticable, _$BoxStylerMixin {
final Prop<Color>? $color;
final Prop<double>? $width;
final Prop<double>? $height;
final Prop<AlignmentGeometry>? $alignment;
// ...
}Generates a _$<Name>Mixin for compound property types with:
merge()— combine mix instancesresolve()— resolve to the target typeprops— equality comparisondebugFillProperties()— diagnostics support
part 'box_constraints_mix.g.dart';
@Mixable()
final class BoxConstraintsMix extends ConstraintsMix<BoxConstraints>
with DefaultValue<BoxConstraints>, Diagnosticable, _$BoxConstraintsMixMixin {
final Prop<double>? $minWidth;
final Prop<double>? $maxWidth;
final Prop<double>? $minHeight;
final Prop<double>? $maxHeight;
// ...
}// Skip setter generation
@MixableField(ignoreSetter: true)
final Prop<Matrix4>? $transform;
// Override the setter parameter type
@MixableField(setterType: List<Shadow>)
final Prop<List<Shadow>>? $shadows;dart run build_runner buildOr within the Mix monorepo:
melos run gen:buildGenerated files use the .g.dart extension and should be committed to version control.
- Set breakpoints in the generator source files under
lib/src/. - Select the "Debug build_runner" launch configuration.
- Press F5.
dart --enable-vm-service=8888 --pause-isolates-on-start run build_runner build --verboseThen connect your debugger to localhost:8888.
- Mix documentation
- mix — Core framework
- mix_annotations — Annotation definitions
- GitHub repository