feat(mix_generator): add @MixableModifier annotation and generator#924
Open
tilucasoli wants to merge 1 commit into
Open
feat(mix_generator): add @MixableModifier annotation and generator#924tilucasoli wants to merge 1 commit into
tilucasoli wants to merge 1 commit into
Conversation
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>
|
To view this pull requests documentation preview, visit the following URL: Documentation is deployed and generated using docs.page. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issue
Adapts #897 to the refactored codegen pipeline on current
main.Description
Adds a
@MixableModifier()annotation and code generator that automatically generatesModifierMixclasses (plus a_$XModifierMethodsmixin withcopyWith/lerp/debugFillProperties/props) fromWidgetModifiersubclasses. 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 (@MixWidgetgenerator) landed. The original PR targeted the pre-#918 structure (MixTypeRegistry,type_mappings.dart,flag_descriptions.dart), which no longer exists.What changed vs. #897
type_metadata.dart(introduced by refactor(mix_generator): simplify codegen pipeline and remove dead code #918) viamixTypeFor,isLerpableType, andflagDescriptionFor, instead of re-adding the removedMixTypeRegistry/type_mappings.dart/flag_descriptions.dart. AddedreverseandvisibletoflagPropertyDescriptionsso the generated bool diagnostics match feat(mix_generator): add @MixableModifier annotation and generator #897 exactly.modifierGeneratoras aSharedPartBuilderalongside the other generators (build_extensions: {'.dart': ['.modifier_generator.g.part']}), so its output combines into the existing single.g.dartviasource_gen:combining_builder— consistent with the current pipeline.errors.darthelpers (requireClassElement,requireName,fail) for uniform diagnostics, matching the other generators.PropWrapperKindandModifierFieldModelare kept self-contained inmodifier_mix_builder.dart(no registry dependency).Changes
mix_annotations: addedMixableModifierannotation +mixableModifierconst, exported from the barrel.mix_generator: addedModifierGenerator,ModifierMixBuilder,ModifierMixinBuilder; registered themodifier_generatorbuilder inbuild.yaml(scoped tolib/src/modifiers/**/*.dart); exposed via the factory andindex.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-writtenModifierMixclasses with generated ones. Complex modifiers (transform, shader_mask, icon_theme, box) remain hand-written.propsorder) andflexint interpolation (MixOps.lerp=lerpDouble().round()).Verification
.g.dartoutput is byte-identical to feat(mix_generator): add @MixableModifier annotation and generator #897 for all 15 modifiers.dart testpasses: 2708 mix tests, 198 mix_generator tests (incl. the 28 new builder tests).dart analyzeis clean formix,mix_generator, andmix_annotations.Review Checklist
🤖 Generated with Claude Code