Skip to content

feat(mix_generator): add @MixableModifier annotation and generator#924

Open
tilucasoli wants to merge 1 commit into
mainfrom
tilucasoli/adapt-pr-897
Open

feat(mix_generator): add @MixableModifier annotation and generator#924
tilucasoli wants to merge 1 commit into
mainfrom
tilucasoli/adapt-pr-897

Conversation

@tilucasoli
Copy link
Copy Markdown
Collaborator

Related issue

Adapts #897 to the refactored codegen pipeline on current main.

Description

Adds a @MixableModifier() annotation and code generator that automatically generates ModifierMix classes (plus a _$XModifierMethods mixin with copyWith/lerp/debugFillProperties/props) from WidgetModifier subclasses. This eliminates ~30–40 lines of boilerplate per modifier.

This is a re-implementation of #897 (branch tilucasoli/gen-modifiers) adapted to the codegen pipeline as it exists today, after #918 (codegen simplification) and #920 (@MixWidget generator) landed. The original PR targeted the pre-#918 structure (MixTypeRegistry, type_mappings.dart, flag_descriptions.dart), which no longer exists.

What changed vs. #897

  • Reuses type_metadata.dart (introduced by refactor(mix_generator): simplify codegen pipeline and remove dead code #918) via mixTypeFor, isLerpableType, and flagDescriptionFor, instead of re-adding the removed MixTypeRegistry / type_mappings.dart / flag_descriptions.dart. Added reverse and visible to flagPropertyDescriptions so the generated bool diagnostics match feat(mix_generator): add @MixableModifier annotation and generator #897 exactly.
  • Wires modifierGenerator as a SharedPartBuilder alongside the other generators (build_extensions: {'.dart': ['.modifier_generator.g.part']}), so its output combines into the existing single .g.dart via source_gen:combining_builder — consistent with the current pipeline.
  • Uses the shared errors.dart helpers (requireClassElement, requireName, fail) for uniform diagnostics, matching the other generators.
  • PropWrapperKind and ModifierFieldModel are kept self-contained in modifier_mix_builder.dart (no registry dependency).

Changes

  • mix_annotations: added MixableModifier annotation + mixableModifier const, exported from the barrel.
  • mix_generator: added ModifierGenerator, ModifierMixBuilder, ModifierMixinBuilder; registered the modifier_generator builder in build.yaml (scoped to lib/src/modifiers/**/*.dart); exposed via the factory and index.dart.
  • mix: applied @MixableModifier() to the 15 eligible modifiers — align, aspect_ratio, blur, clip, default_text_style, flexible, fractionally_sized_box, intrinsic, mouse_cursor, opacity, padding, rotated_box, scroll_view, sized_box, visibility — replacing the hand-written ModifierMix classes with generated ones. Complex modifiers (transform, shader_mask, icon_theme, box) remain hand-written.
  • Tests: 28 new builder unit tests; updated 7 modifier tests for the generator's alphabetical field ordering (affects props order) and flex int interpolation (MixOps.lerp = lerpDouble().round()).

Verification

Review Checklist

  • Testing: unit tests for the builders + existing modifier tests pass.
  • Breaking Changes: none — public modifier constructors are unchanged (positional/named shapes preserved).
  • Documentation Updates
  • Website Updates

🤖 Generated with Claude Code

Adds a `@MixableModifier()` annotation and code generator that
generates the `_$XModifierMethods` mixin (copyWith, lerp,
debugFillProperties, props) and a standalone `ModifierMix` class
(create/public constructors, resolve, merge, debugFillProperties,
props) from `WidgetModifier` subclasses. This removes ~30-40 lines of
boilerplate per modifier.

Adapted from #897 to the post-#918/#920 codegen pipeline:
- Uses the consolidated `type_metadata.dart` helpers (`mixTypeFor`,
  `isLerpableType`, `flagDescriptionFor`) instead of the removed
  `MixTypeRegistry` / `type_mappings.dart` / `flag_descriptions.dart`.
- Wires `modifierGenerator` as a `SharedPartBuilder` alongside the
  other generators, so output is combined into the existing `.g.dart`.
- Reuses the shared `errors.dart` helpers (`requireClassElement`,
  `requireName`, `fail`) for uniform diagnostics.
- Adds `reverse`/`visible` to `flagPropertyDescriptions` so the bool
  diagnostics match the original PR.

Applies `@MixableModifier()` to the 15 eligible modifiers (align,
aspect_ratio, blur, clip, default_text_style, flexible,
fractionally_sized_box, intrinsic, mouse_cursor, opacity, padding,
rotated_box, scroll_view, sized_box, visibility). Complex modifiers
(transform, shader_mask, icon_theme, box) remain hand-written.

Generated output is byte-identical to #897. Adds 28 builder unit
tests; all mix and mix_generator tests pass and analyze is clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@docs-page
Copy link
Copy Markdown

docs-page Bot commented May 29, 2026

To view this pull requests documentation preview, visit the following URL:

docs.page/btwld/mix~924

Documentation is deployed and generated using docs.page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant