Skip to content

Support color contrast-based theme determining #182863

Description

@xxxOVALxxx

Use case

Currently, Flutter handles accessibility contrast as a boolean value (MediaQuery.highContrast, MaterialApp.highContrastTheme). This aligns with iOS's binary "Increase Contrast" toggle, where high contrast is either on or off.

But Android supports floating-point contrast levels ranging from -1.0 to 1.0 (where 0.0 is standard, 0.5 is medium, 1.0 is high, and negative values represent lower contrast)

Proposal

First, we need to implement contrast retrieval on all available platforms. Currently, contrast retrieval is implemented using the boolean value via MediaQuery.highContrast and only on iOS (it will be available on Android after this PR is merged).

Second, since highContrastTheme only expects a static ThemeData object, we need a new approach. Here are the options I came up with:

A. Merge into a single theme resolver
theme: (double contrast) => ThemeData(...)

B. Keep the existing theme and highContrastTheme as static ThemeData objects, but use contrast to automatically interpolate between them

if (contrast > 0.0 && highContrastTheme != null) {
  return ThemeData.lerp(theme, highContrastTheme, contrast);
}

C. Instead of swapping entire themes, adjust the ColorScheme dynamically based on the contrast

MaterialApp(
  theme: ThemeData(
    colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue).withContrast(contrast),
  ),
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)c: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.team-accessibilityOwned by Framework Accessibility team (i.e. responsible for accessibility code in flutter/flutter)triaged-accessibilityTriaged by Framework Accessibility team

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions