Skip to content

Fixes #173514 : Add highContrastThemeMode parameter to MaterialApp #173520

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

AnuragTiwari1508
Copy link

Fixes #173514

Description

Added support for manual high contrast theme mode control in MaterialApp. This allows developers to explicitly control the high contrast theme mode independently of the system settings, similar to how themeMode works for light/dark themes.

Changes include:

  • Added HighContrastThemeMode enum with system, enabled, and disabled values
  • Added highContrastThemeMode property to MaterialApp
  • Updated theme resolution logic to respect manual high contrast settings
  • Added comprehensive test coverage

Test Plan

Added new test cases in packages/flutter/test/material/app_test.dart covering:

  • Default behavior (system)
  • Explicit enable/disable
  • Interaction with platform settings
  • State restoration
  • Theme inheritance

All tests are passing.

Breaking Change

No breaking changes. This is a new opt-in feature that maintains backward compatibility with existing apps.

This commit adds a new highContrastThemeMode parameter to MaterialApp that allows developers to manually control high contrast theme selection, addressing the need for apps to provide manual high contrast toggles when platform support is not available.

Changes:
- Added HighContrastThemeMode enum with system, standard, and highContrast options
- Added highContrastThemeMode parameter to MaterialApp constructor
- Modified _themeBuilder to respect the new parameter
- Added comprehensive tests for all modes and edge cases

The new parameter defaults to HighContrastThemeMode.system to maintain backward compatibility while enabling manual control when needed.

Fixes: flutter#168288
Copy link

google-cla bot commented Aug 10, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Aug 10, 2025
Copy link
Contributor

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

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 a highContrastThemeMode to MaterialApp, allowing developers to override the system's high contrast setting. The implementation is solid, with good documentation and comprehensive tests. My main feedback is to improve the clarity of the new HighContrastThemeMode enum by using more explicit names for its values, which would enhance the readability of the new API.

Comment on lines 70 to 80
enum HighContrastThemeMode {
/// Use either the standard or high contrast theme based on what the user has selected in
/// the system settings.
system,

/// Always use the standard theme regardless of system preference.
standard,

/// Always use the high contrast theme regardless of system preference.
highContrast,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The enum values standard and highContrast could be clearer. The term standard is a bit ambiguous, as it could be interpreted as 'the standard high contrast theme'.1

Your PR description mentions enabled and disabled values, which are more explicit about the state of the high contrast feature. Consider renaming standard to disabled and highContrast to enabled for better readability and to align with the terminology in the PR description.

If you apply this change, remember to update the usages throughout the file (constructors, logic, and documentation for highContrastThemeMode) and in the tests.

enum HighContrastThemeMode {
  /// Use either the standard or high contrast theme based on what the user has selected in
  /// the system settings.
  system,

  /// Always use the standard theme (high contrast disabled) regardless of system preference.
  disabled,

  /// Always use the high contrast theme (high contrast enabled) regardless of system preference.
  enabled,
}

Style Guide References

Footnotes

  1. Code should be optimized for readability. Using more explicit enum names like disabled and enabled improves readability over the more ambiguous standard. (link)

- Rename 'standard' to 'disabled' for better clarity
- Rename 'highContrast' to 'enabled' for consistency
- Update all documentation and test references
- Addresses code review feedback for improved readability
@AnuragTiwari1508 AnuragTiwari1508 requested a review from a team as a code owner August 11, 2025 03:58
@github-actions github-actions bot added tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Aug 11, 2025
@AnuragTiwari1508 AnuragTiwari1508 force-pushed the feature/high-contrast-theme-mode branch from 24a87d8 to c9cff0e Compare August 11, 2025 05:53
@fluttergithubbot
Copy link
Contributor

An existing Git SHA, c9cff0eff643c2d61de8ee50c168f62729bd2b4c, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@github-actions github-actions bot removed tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team labels Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow manually setting the theme contrast mode
2 participants