Skip to content

[Material] Resolve overlay color for pressed/active/inactive states in selection controls#71569

Merged
fluttergithubbot merged 4 commits intoflutter:masterfrom
perclasson:overlay_color_in_selection_controls
Dec 7, 2020
Merged

[Material] Resolve overlay color for pressed/active/inactive states in selection controls#71569
fluttergithubbot merged 4 commits intoflutter:masterfrom
perclasson:overlay_color_in_selection_controls

Conversation

@perclasson
Copy link
Contributor

@perclasson perclasson commented Dec 2, 2020

Description

Resolve overlay color for pressed/active/inactive states in selection controls (Checkbox, Radio and Switch) and their corresponding themes (CheckboxThemeData, RadioThemeData and SwitchThemeData).

This allows you to set the overlayColor for the selection control and its themes, to for example have a different pressed overlay color when a Checkbox is selected or not:

Screenshot Code
Screenshot of Checkbox with overlay color
bool? _value = false;

Checkbox(
  value: _value,
  tristate: true,
  onChanged: (bool? value) {
    setState(() {
      _value = value;
    });
  },
  overlayColor: MaterialStateProperty.resolveWith((Set<MaterialState> states) {
    if (states.contains(MaterialState.pressed)) {
      if (states.contains(MaterialState.selected)) {
        return Theme.of(context).colorScheme.primary.withOpacity(0.12);
      }
      return Colors.grey.withOpacity(0.12);
    }
  }),
)

Related Issues

Closes #70828

Tests

I added the following tests:

  • Checkbox overlay color resolves in active/pressed/focused/hovered states
  • Checkbox theme overlay color resolves in active/pressed states
  • Tristate Checkbox overlay color resolves in pressed active/inactive states
  • Radio overlay color resolves in active/pressed/focused/hovered states
  • Radio theme overlay color resolves in active/pressed states
  • Switch overlay color resolves in active/pressed/focused/hovered states
  • Switch theme overlay color resolves in active/pressed states

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Dec 2, 2020
@google-cla google-cla bot added the cla: yes label Dec 2, 2020
@perclasson perclasson changed the title [Material] Resolve overlay color pressed active/inactive states for selection controls [Material] Resolve overlay color for pressed/active/inactive states in selection controls Dec 2, 2020
Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

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

  _    ___ _____ __  __ 
 | |  / __|_   _|  \/  |
 | |_| (_ | | | | |\/| |
 |____\___| |_| |_|  |_|
                        

@perclasson perclasson requested a review from HansMuller December 2, 2020 16:26
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Make it possible to change the pressed overlay color for selection controls

5 participants