Skip to content

[material_ui] Add contrastLevel for M3 ColorScheme - #11801

Open
QuncCccccc wants to merge 18 commits into
flutter:m3e_migrationfrom
QuncCccccc:color_scheme_udpate
Open

[material_ui] Add contrastLevel for M3 ColorScheme#11801
QuncCccccc wants to merge 18 commits into
flutter:m3e_migrationfrom
QuncCccccc:color_scheme_udpate

Conversation

@QuncCccccc

@QuncCccccc QuncCccccc commented May 29, 2026

Copy link
Copy Markdown
Contributor

Fixes flutter/flutter#184951

This PR is to add medium- and high-contrast M3 ColorScheme baselines. I also added a double? contrastLevel to ThemeData.

By default, ThemeData() shows standard M3 ColorScheme. To choose medium/high contrast, use

ThemeData(
  // brightness: Brightness.dark shows dark version of the baselines.
  contrastLevel: ContrastLevel.medium, // ContrastLevel.high
)

This change will not cause breaking changes because the standard-contrast m3 color scheme baseline stays the same.

Screenshot 2026-07-31 at 4 35 36 PM

TODO:
Add an example or update an existing example to reflect the new feature.

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I followed [the version and CHANGELOG instructions], using [semantic versioning] and the [repository CHANGELOG style], or I have commented below to indicate which documented exception this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label May 29, 2026
@github-actions github-actions Bot added triage-framework Should be looked at in framework triage p: material_ui labels May 29, 2026
@QuncCccccc
QuncCccccc force-pushed the color_scheme_udpate branch 4 times, most recently from de5b083 to 6d663fa Compare July 23, 2026 18:29
@QuncCccccc
QuncCccccc force-pushed the color_scheme_udpate branch from 8ce2d9e to 4513c4f Compare July 30, 2026 18:56
@QuncCccccc
QuncCccccc force-pushed the color_scheme_udpate branch from 4513c4f to e293b35 Compare July 30, 2026 22:53
stdout.writeln('Generating contents...');
}
final String contents = generateContents(_className);
final String contents = generateContents(requiresGeneratedClass ? _className : '');

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a class for ColorScheme, so I added a requiresGeneratedClass field.

@QuncCccccc
QuncCccccc requested a review from elliette July 31, 2026 23:40
@QuncCccccc
QuncCccccc requested a review from Piinks July 31, 2026 23:40
@QuncCccccc
QuncCccccc marked this pull request as ready for review July 31, 2026 23:40

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Material 3 contrast levels in ThemeData by adding a contrastLevel parameter to the constructor. This allows standard, medium, high, or custom contrast levels to be applied when generating or selecting a ColorScheme. The generation of default color schemes is migrated to a new template (ColorSchemeTemplateM3), and corresponding unit tests are added. Feedback on the changes points out a broken documentation link referencing a non-existent public ThemeData.contrastLevel property, suggesting it be updated to refer to the constructor parameter instead.

Comment on lines +211 to +213
/// A custom `double` between -1.0 and 1.0 can also be passed to
/// [ThemeData.contrastLevel] when [ThemeData.colorSchemeSeed] is provided, in
/// which case the value is passed to [ColorScheme.fromSeed].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation references [ThemeData.contrastLevel], but ThemeData does not actually have a public contrastLevel property or getter (similar to colorSchemeSeed). This results in a broken documentation link. We should update the documentation to refer to the constructor parameter instead.

/// A custom double between -1.0 and 1.0 can also be passed as the
/// contrastLevel parameter of the [ThemeData] constructor when
/// [ThemeData.colorSchemeSeed] is provided, in which case the value is passed
/// to [ColorScheme.fromSeed].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated documentation.

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

Labels

CICD Run CI/CD p: material_ui triage-framework Should be looked at in framework triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant