Skip to content

feat(mix): override non-deprecated Color methods on ColorRef with directives#908

Merged
tilucasoli merged 5 commits intomainfrom
tilucasoli/colorref-overrides
Apr 23, 2026
Merged

feat(mix): override non-deprecated Color methods on ColorRef with directives#908
tilucasoli merged 5 commits intomainfrom
tilucasoli/colorref-overrides

Conversation

@tilucasoli
Copy link
Copy Markdown
Collaborator

Related issue

None.

Description

Makes the fluent Color transform API usable on ColorRef. Previously, calling colorToken().withAlpha(128) (or any other Color method) on a token reference threw UnimplementedError via ValueRef.noSuchMethod. Now those calls append the matching *ColorDirective to the underlying Prop<Color> and return a new ColorRef, so transforms can be chained and are applied at resolution time.

Changes

  • ColorRef (packages/mix/lib/src/theme/tokens/token_refs.dart): override withValues, withAlpha, withRed, withGreen, withBlue, and withOpacity. Each constructs the matching existing directive (WithValuesColorDirective, AlphaColorDirective, WithRedColorDirective, WithGreenColorDirective, WithBlueColorDirective, OpacityColorDirective), appends it via Prop.directives(...), and wraps the result in a new ColorRef.
  • Accessors (a, r, g, b, colorSpace, toARGB32, computeLuminance) and deprecated int getters continue to fall through to ValueRef.noSuchMethod with the existing helpful error (scoped non-goal, covered by a regression test).
  • Unit tests: new ColorRef Color method overrides group in prop_refs_test.dart covering each override, chained-directive order, resolution through MockBuildContext, and the regression guard.
  • End-to-end test: new color_token_integration_test.dart that wires ColorToken() → fluent ColorRefBoxStyler().color(...)Box rendered inside a MixScope, and asserts the resolved BoxDecoration.color equals the Flutter-native transform applied to the token value.

Review Checklist

  • Testing: Have you tested your changes, including unit tests and integration tests for affected code?
  • Breaking Changes: Does this change introduce breaking changes affecting existing code or users?
  • Documentation Updates: Are all relevant documentation files (e.g. README, API docs) updated to reflect the changes in this PR?
  • Website Updates: Is the website containing the updates you make on documentation?

Additional Information (optional)

Calls to the six transform methods now return a ColorRef (concrete) typed as Color (interface) — consistent with how other *Ref types behave. The withOpacity override is intentionally not re-annotated @Deprecated on ColorRef; callers through the Color interface still see Flutter's upstream deprecation.

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.
@docs-page
Copy link
Copy Markdown

docs-page Bot commented Apr 23, 2026

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

docs.page/btwld/mix~908

Documentation is deployed and generated using docs.page.

@github-actions github-actions Bot added the mix label Apr 23, 2026
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tilucasoli tilucasoli merged commit e7e8c00 into main Apr 23, 2026
4 checks passed
@tilucasoli tilucasoli deleted the tilucasoli/colorref-overrides branch April 23, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant