Skip to content

Add wrapper-class output style option for generated colors#766

Open
ugoostanleyibe wants to merge 2 commits into
FlutterGen:mainfrom
ugoostanleyibe:improve-color-gen
Open

Add wrapper-class output style option for generated colors#766
ugoostanleyibe wants to merge 2 commits into
FlutterGen:mainfrom
ugoostanleyibe:improve-color-gen

Conversation

@ugoostanleyibe
Copy link
Copy Markdown

@ugoostanleyibe ugoostanleyibe commented Jun 7, 2026

What does this change?

Adds a wrapper-class output style option so generated colors are a Color subtype (usable with dot shorthands)

Fixes #765 🎯

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist:

Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open a GitHub issue as a bug/feature request before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
    • Ensure the tests (melos run test)
    • Ensure the analyzer and formatter pass (melos run format to automatically apply formatting)
  • Appropriate docs were updated (if necessary)

ugoostanleyibe and others added 2 commits June 5, 2026 23:05
Add an opt-in `colors/outputs/style` option to the colors generator.

The new `wrapper-class` style generates a color class that `extends Color`
with a forwarding const constructor, exposing each color as a `static const`
of the generated type (no explicit annotation). Material colors additionally
emit a `<name>Swatch` (MaterialColor) / `<name>AccentSwatch`
(MaterialAccentColor) alongside the base color.

The default `plain` style (`abstract final class` with `static const Color`)
is unchanged and remains the default, so existing users are unaffected.

- Add FlutterGenElementColorsOutputsStyle enum + FlutterGenElementColorsOutputs
- Branch colors_generator on the configured style
- Default config + README documentation
- Tests: new fixture/fact, generator test case, enum fromJson/toJson tests
- Showcase the new style in the example apps

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The wrapper-class color style was incorrectly emitting an extra base
`<name>` constant and appending a `Swatch` suffix to every material color.
Material colors already carry their own names in the source XML (e.g. a
`seaBlueSwatch` material entry alongside a separate `seaBlue` normal color),
so this produced duplicated/`SwatchSwatch` output.

Material and material-accent colors are now emitted identically to the
`plain` style. Only normal colors change in the wrapper-class style (they use
the generated type's const constructor with no annotation).

- Fix _colorStatement; regenerate fixture fact and example output
- Restore example main.dart primarySwatch to the material color name
- Correct README/CHANGELOG/doc-comment wording

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ugoostanleyibe ugoostanleyibe changed the title Improve color gen Add wrapper-class output style option for generated colors Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR]: add wrapper-class output style so generated colors are a Color subtype (usable with dot shorthands)

1 participant