Skip to content

[material_ui] Add contrastLevel for M3 ColorScheme - #12743

Merged
auto-submit[bot] merged 19 commits into
flutter:mainfrom
QuncCccccc:color_scheme_update_main
Sep 22, 2026
Merged

auto-submit[bot] merged 19 commits into
flutter:mainfrom
QuncCccccc:color_scheme_update_main

Conversation

@QuncCccccc

@QuncCccccc QuncCccccc commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

This PR is to port #11801

Original PR Description

Fixes flutter/flutter#184951
Fixes flutter/flutter#188409

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.

@github-actions github-actions Bot added p: material_ui triage-design Should be looked at in design triage labels Sep 3, 2026
@QuncCccccc QuncCccccc added the CICD Run CI/CD label Sep 10, 2026
@QuncCccccc
QuncCccccc marked this pull request as ready for review September 10, 2026 22:44

@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 adds support for standard, medium, and high contrast Material 3 color scheme baselines by introducing a contrastLevel parameter to ThemeData and generating the corresponding default color schemes. It also adds a ContrastLevel class with predefined contrast values, updates the default generation tools, and includes tests for the new contrast levels. A review comment notes that while contrastLevel is added to the ThemeData constructor, it is not declared as a field on ThemeData, which prevents public access, breaks copying via copyWith, and excludes it from equality, hashing, and debugging properties.

contrastLevel == null || (contrastLevel >= -1.0 && contrastLevel <= 1.0),
'contrastLevel must be between -1.0 and 1.0 inclusive.',
);
contrastLevel ??= ContrastLevel.standard;

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.

looking at this factory, do you know why we assign default value here instead of in the parameter list directly like

factory ThemeData({
  double contrastLevel = ContrastLevel.standard,
});

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.

I traced this back through ThemeData history. Since the ThemeData/ThemeData.raw split was introduced, the public factory has treated its parameters as optional inputs and resolved their effective defaults in the implementation before constructing ThemeData.raw. For consistency with that existing ThemeData convention, I kept contrastLevel nullable and resolved ContrastLevel.standard in the factory body. I couldn’t find a formal style rule requiring this, though.

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.

we should prefer parameter with default value if possible as that makes the parameter non-nullable. but that can be a separate pr

@chunhtai
chunhtai self-requested a review September 16, 2026 16:26
@QuncCccccc
QuncCccccc force-pushed the color_scheme_update_main branch from fdcde10 to a04411b Compare September 17, 2026 21:09

@chunhtai chunhtai 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.

LGTM, just a minor comment

@QuncCccccc
QuncCccccc force-pushed the color_scheme_update_main branch from a04411b to b62b641 Compare September 19, 2026 22:28
@QuncCccccc
QuncCccccc force-pushed the color_scheme_update_main branch from d12d5cf to 48b3179 Compare September 22, 2026 19:18
@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 22, 2026
@auto-submit
auto-submit Bot merged commit 0dfacae into flutter:main Sep 22, 2026
13 checks passed
pull Bot pushed a commit to edisplay/flutter that referenced this pull request Sep 24, 2026
Roll Packages from c2b58e1 to 431ea69 (56 revisions)

flutter/packages@c2b58e1...431ea69

2026-09-24 [email protected] [cross_file]
Updates cross_file to a package separated federated plugin
(flutter/packages#11010)
2026-09-23 [email protected] [material_ui]
Remove static access of `copyWith` from `dart fix` golden tests for
`ThemeData/TextTheme` (flutter/packages#12994)
2026-09-23 [email protected] [camera_avfoundation] Replace
deprecated high-resolution capture APIs (flutter/packages#12372)
2026-09-23 [email protected] [pigeon] update nullish checks to use
new isNullish method (flutter/packages#12985)
2026-09-23 [email protected] [ci] Assign batch release PR approver
as reviewer on sync-back PR (flutter/packages#12976)
2026-09-23 [email protected] [image_picker] Fix scaling 10-bit images
(flutter/packages#12557)
2026-09-23 [email protected] [material_ui] Improve
Autocomplete, DrawerHeader, and Tooltip accessibility
(flutter/packages#12918)
2026-09-23 [email protected] [google_fonts] Decouple GoogleFontsLite
for full tree-shaking and add full feature parity
(flutter/packages#12830)
2026-09-23 [email protected] [file_selector]
Ignore flakey `file_selector_android` tests (flutter/packages#12992)
2026-09-23 [email protected] [CI] Remove
bringup from `Mac_arm64 build_all_packages` targets
(flutter/packages#12978)
2026-09-22 [email protected] [material_ui]
Unskip 5 passing web tests in bottom_app_bar_test and text_field_test
(flutter/packages#12983)
2026-09-22 [email protected]
[cupertino_ui] Unskip 5 passing web tests in
adaptive_text_selection_toolbar_test and text_field_test
(flutter/packages#12984)
2026-09-22 [email protected] [go_router] Fix ShellRoute chrome dropped
from semantics tree by ModalBarrier (flutter/packages#12353)
2026-09-22 [email protected] [material_ui]
Add contrastLevel for M3 ColorScheme (flutter/packages#12743)
2026-09-22 [email protected] [go_router] Preserve nested pushes
during config updates (flutter/packages#12611)
2026-09-22 [email protected] [material_ui]
Migrate M3 Chip template to use new gen_defaults
(flutter/packages#12847)
2026-09-22 [email protected] [material_ui] Fix
LocalHistoryEntry leak when double tapping Drawer scrim
(flutter/packages#12552)
2026-09-22 [email protected] Update suggested reviewers
(flutter/packages#12974)
2026-09-22 [email protected] Sync release-material_ui-1.4.0 to
main (flutter/packages#12966)
2026-09-22 [email protected] Sync release-cupertino_ui-1.1.1 to
main (flutter/packages#12965)
2026-09-21 [email protected] [ci] Update repo
for 3.47 stable release (flutter/packages#12959)
2026-09-21 [email protected] Manual roll Flutter from
27fec0e to 4fcd90b (1 revision) (flutter/packages#12904)
2026-09-21 [email protected] Revert "[go_router_builder] Migrate to
material_ui" (flutter/packages#12962)
2026-09-21 [email protected]
[material_ui] Update `material_ui` tests to prevent them from failing
when framework `TextStyle` changes (flutter/packages#12728)
2026-09-21 [email protected] [go_router_builder] Migrate to
material_ui (flutter/packages#12913)
2026-09-21 [email protected] [material_ui,
cupertino_ui] Bump Flutter version from to 3.47 (flutter/packages#12944)
2026-09-21 [email protected] [cupertino_ui] Work around dart2wasm
optional parameter inference bug in example checkbox tests
(flutter/packages#12961)
2026-09-21 [email protected] [cupertino_ui] Work around dart2wasm
optional parameter inference bug in checkbox_test.dart
(flutter/packages#12956)
2026-09-21 [email protected] [google_sign_in] PR 3/4 Migrate
ViewProvider and GID SDK wrappers from Objective-C to Swift
(flutter/packages#12657)
2026-09-21 [email protected] [google_sign_in] PR 2/4 Migrate
the plugin class from Objective-C to Swift. (flutter/packages#12655)
2026-09-20 [email protected]
[cross_file_darwin] iOS/macOS implementation of `cross_file`
(flutter/packages#12910)
2026-09-20 [email protected]
[cross_file_web] Web implementation of `cross_file`
(flutter/packages#12908)
2026-09-20 [email protected] [material_ui]
Migrate M3 `InputChip` template to use new gen_defaults
(flutter/packages#12850)
2026-09-20 [email protected] [material_ui]
Migrate M3 Checkbox defaults to new gen_defaults
(flutter/packages#12816)
2026-09-20 [email protected] [material_ui]
Migrate M3 `FilterChip` template to use new gen_defaults
(flutter/packages#12849)
2026-09-19 [email protected] [material_ui] Announce PopupMenuButton with a
child as a button (flutter/packages#12585)
2026-09-19 [email protected] Roll Flutter (stable) from
9584c67 to 6a19cca (7 revisions) (flutter/packages#12950)
2026-09-18 [email protected] [material_ui]
Reduce the `material_ui` non-wasm web test suite
(flutter/packages#12763)
2026-09-18 [email protected] Replace
`Mac_x64` builders with `Mac_arm64` ones (flutter/packages#12941)
2026-09-18 [email protected]
[in_app_purchase_storekit] Use `_$SKPaymentDiscountWrapperToJson`
(flutter/packages#12721)
2026-09-18 [email protected] [In_app _purchase] README
excerpt examples and changelog (flutter/packages#12739)
2026-09-18 [email protected] [material_ui] Add alternative
input method for `RangeSlider` in `NavigationMode.directional`
(flutter/packages#12630)
2026-09-18 [email protected]
[cross_file_android] Android implementation of `cross_file`
(flutter/packages#12909)
2026-09-18 [email protected]
[camera_platform_interface] Adds videoOutputPath support to
startVideoRecording (flutter/packages#12667)
2026-09-17 [email protected] [cupertino_ui] Migrate a
snippet in `CupertinoCheckbox`'s API doc to `{@example}` and add unit
tests (flutter/packages#12180)
2026-09-17 [email protected] [material_ui]
Default gen_defaults color helper prefix (flutter/packages#12848)
...
vashworth pushed a commit to vashworth/packages that referenced this pull request Sep 24, 2026
This PR is to port flutter#11801

### Original PR Description

Fixes flutter/flutter#184951
Fixes flutter/flutter#188409

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.

<img width="1181" height="526" alt="Screenshot 2026-07-31 at 4 35 36 PM" src="https://github.com/user-attachments/assets/0515a722-1455-49a0-9c5d-30ffaa844b7f" />

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

## Pre-Review Checklist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: material_ui triage-design Should be looked at in design triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

color_scheme_template.dart M3 Expressive: Colors

3 participants