feat(mix): override non-deprecated Color methods on ColorRef with directives#908
Merged
tilucasoli merged 5 commits intomainfrom Apr 23, 2026
Merged
feat(mix): override non-deprecated Color methods on ColorRef with directives#908tilucasoli merged 5 commits intomainfrom
tilucasoli merged 5 commits intomainfrom
Conversation
ColorRef now overrides withValues, withAlpha, withRed, withGreen, withBlue, and withOpacity. Each call appends the matching *ColorDirective to the underlying Prop<Color> and returns a new ColorRef, so transforms can be chained fluently on a token reference and are applied at resolution time. Accessors (a, r, g, b, colorSpace, toARGB32, computeLuminance) and the deprecated int getters continue to throw via ValueRef.noSuchMethod.
Exercises the full public API: ColorToken() -> ColorRef.withAlpha / withRed / withGreen / withBlue / withValues / withOpacity -> BoxStyler -> Box rendered inside a MixScope. Verifies the resolved BoxDecoration color matches the directive transform applied to the token's value.
Reverted per user request — the design document lives in conversation/PR context rather than in-repo.
|
To view this pull requests documentation preview, visit the following URL: Documentation is deployed and generated using docs.page. |
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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
None.
Description
Makes the fluent
Colortransform API usable onColorRef. Previously, callingcolorToken().withAlpha(128)(or any otherColormethod) on a token reference threwUnimplementedErrorviaValueRef.noSuchMethod. Now those calls append the matching*ColorDirectiveto the underlyingProp<Color>and return a newColorRef, so transforms can be chained and are applied at resolution time.Changes
ColorRef(packages/mix/lib/src/theme/tokens/token_refs.dart): overridewithValues,withAlpha,withRed,withGreen,withBlue, andwithOpacity. Each constructs the matching existing directive (WithValuesColorDirective,AlphaColorDirective,WithRedColorDirective,WithGreenColorDirective,WithBlueColorDirective,OpacityColorDirective), appends it viaProp.directives(...), and wraps the result in a newColorRef.a,r,g,b,colorSpace,toARGB32,computeLuminance) and deprecated int getters continue to fall through toValueRef.noSuchMethodwith the existing helpful error (scoped non-goal, covered by a regression test).ColorRef Color method overridesgroup inprop_refs_test.dartcovering each override, chained-directive order, resolution throughMockBuildContext, and the regression guard.color_token_integration_test.dartthat wiresColorToken()→ fluentColorRef→BoxStyler().color(...)→Boxrendered inside aMixScope, and asserts the resolvedBoxDecoration.colorequals the Flutter-native transform applied to the token value.Review Checklist
Additional Information (optional)
Calls to the six transform methods now return a
ColorRef(concrete) typed asColor(interface) — consistent with how other*Reftypes behave. ThewithOpacityoverride is intentionally not re-annotated@DeprecatedonColorRef; callers through theColorinterface still see Flutter's upstream deprecation.