Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support detection of light and dark system colors #164933

Merged
merged 7 commits into from
Mar 12, 2025

Conversation

mdebbar
Copy link
Contributor

@mdebbar mdebbar commented Mar 10, 2025

Part of #118853

This PR is an enhancement to #163335 to provide detection of system colors for both light and dark mode. This is needed for the construction of a highContrastTheme and highContrastDarkTheme.

@mdebbar mdebbar requested review from yjbanov and chunhtai March 10, 2025 20:45
@github-actions github-actions bot added engine flutter/engine repository. See also e: labels. platform-web Web applications specifically labels Mar 10, 2025
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

Can you talk a bit more about the changes about this pr? It looks like this pr attempt to detect color palette for both light and dart modes? I thought the browser should be able to know whether the system setting is right? In that case, shouldn't we only need to provide the color palette that matches the current browser setting?

final class SystemColorPalette {
SystemColorPalette._(this.brightness);

/// A palette of system colors for light mode.
Copy link
Contributor

Choose a reason for hiding this comment

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

will the value for light or dark change based on the light/dark setting of the browser?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. The user can get both light and dark system colors, regardless of system brightness settings.

@mdebbar
Copy link
Contributor Author

mdebbar commented Mar 11, 2025

Can you talk a bit more about the changes about this pr?

Sure! Let me explain the steps that got me here:

  1. Before this PR, the browser was only providing "light" system colors. Even when I change my system to dark mode, the browser still gives us the same "light" colors.
  2. I investigated and did some reading online and found out that we have to tell the browser which modes we support (light and dark). If we don't, the browser assumes that we only support light.
  3. The way the MaterialApp widget works is by taking a highContrastTheme and highContrastDarkTheme (similar to how it takes a theme and darkTheme). And then it internally decides which one to use based on platformBrightness (which is provided by the system).
  4. So I think the most convenient API for the user is to expose both light and dark system colors. That makes it possible to create a light theme and a dark theme and let MaterialApp switch between the two.

@mdebbar mdebbar requested a review from chunhtai March 11, 2025 18:40
Copy link
Contributor

@chunhtai chunhtai left a comment

Choose a reason for hiding this comment

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

LGTM

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 11, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 11, 2025
Copy link
Contributor

auto-submit bot commented Mar 11, 2025

autosubmit label was removed for flutter/flutter/164933, because - The status or check suite Linux analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 11, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 11, 2025
Copy link
Contributor

auto-submit bot commented Mar 11, 2025

autosubmit label was removed for flutter/flutter/164933, because - The status or check suite Linux analyze has failed. Please fix the issues identified (or deflake) before re-applying this label.

@mdebbar mdebbar added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 12, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Mar 12, 2025
Merged via the queue into flutter:master with commit 212f66f Mar 12, 2025
169 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 12, 2025
@mdebbar mdebbar deleted the detect_light_and_dark branch March 12, 2025 17:16
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 16, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 17, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine flutter/engine repository. See also e: labels. platform-web Web applications specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants