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

[Material] Add support for hovered, pressed, focused, and selected text color on Chips. #37259

Merged
merged 5 commits into from Aug 3, 2019

Conversation

@johnsonmh
Copy link
Contributor

commented Jul 30, 2019

Description

This change updates Chips to support MaterialStateProperty<Color> for text color on chips. This allows for fully customizable text colors for every state that a chip can be in.

For example, you can accomplish the following customized chip

giphy

Using the following code snippet:

final textColor = MaterialStateColor.resolveWith((states) {
  if (states.contains(MaterialState.selected)) {
    if (states.contains(MaterialState.pressed)) {
      return Colors.blue[900];
    }
    return Colors.blue[600];
  }
  if (states.contains(MaterialState.pressed)) {
    return Colors.black;
  }
  return Colors.grey[700];
});


ChoiceChip(
  ...
  labelStyle: TextStyle(color: textColor),
);

Tests

I added the following tests:

  • Test a chip with a stateful color in all of the states to make sure that states are properly tracked, and colors is used correctly.
  • Test that the above can also be accomplished using only the theme.

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 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

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.
johnsonmh added 2 commits Jul 30, 2019
@googlebot googlebot added the cla: yes label Jul 30, 2019
@johnsonmh johnsonmh changed the title [Material] [Material] Add support for hovered, pressed, focused, and selected text color on Chips. Jul 30, 2019
@johnsonmh johnsonmh requested review from willlarche, clocksmith and rami-a Jul 30, 2019
@rami-a
rami-a approved these changes Jul 31, 2019
Copy link
Contributor

left a comment

LGTM!

@johnsonmh johnsonmh requested a review from HansMuller Jul 31, 2019
Copy link
Contributor

left a comment

LGTM after the !widget.isEnabled ?? false expressions are sorted.

@@ -1416,6 +1428,8 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
void initState() {
assert(widget.onSelected == null || widget.onPressed == null);
super.initState();
_updateState(MaterialState.disabled, !widget.isEnabled ?? false);

This comment has been minimized.

Copy link
@HansMuller

HansMuller Aug 2, 2019

Contributor

How could !widget.isEnabled be null (and we assert that isEnabled is non-null)? Likewise for the next line and similar expressions below.

This comment has been minimized.

Copy link
@johnsonmh

johnsonmh Aug 2, 2019

Author Contributor

Good call, we actually already assert isEnabled != null, so I removed the ?? false here. I'm worried about doing the same thing for selected, because in our tests (and possibly users code) we do something like selected: isSelectable ? _selected : null.

selected: isSelectable ? value : null,

@@ -47,12 +49,10 @@ IconThemeData getIconData(WidgetTester tester) {

DefaultTextStyle getLabelStyle(WidgetTester tester) {
return tester.widget(
find
.descendant(
find.descendant(

This comment has been minimized.

Copy link
@HansMuller

HansMuller Aug 2, 2019

Contributor

NICE

@johnsonmh johnsonmh merged commit da8c7a9 into flutter:master Aug 3, 2019
78 of 79 checks passed
78 of 79 checks passed
tool_coverage-linux Task Summary
Details
WIP Ready for review
Details
add2app-macos Task Summary
Details
add2app-macos
Details
analyze Task Summary
Details
analyze
Details
build_tests-linux Task Summary
Details
build_tests-linux
Details
build_tests-macos Task Summary
Details
build_tests-macos
Details
build_tests-windows Task Summary
Details
build_tests-windows
Details
cla/google All necessary CLAs are signed
customer_testing-linux Task Summary
Details
customer_testing-linux
Details
customer_testing-macos Task Summary
Details
customer_testing-macos
Details
customer_testing-windows Task Summary
Details
customer_testing-windows
Details
deploy_gallery Task Summary
Details
deploy_gallery
Details
deploy_gallery-macos Task Summary
Details
deploy_gallery-macos
Details
docs Task Summary
Details
docs
Details
flutter-build
Details
integration_tests-linux Task Summary
Details
integration_tests-linux
Details
integration_tests-macos Task Summary
Details
integration_tests-macos
Details
integration_tests-windows Task Summary
Details
integration_tests-windows
Details
integration_tests_gradle1-linux Task Summary
Details
integration_tests_gradle1-linux
Details
integration_tests_gradle1-windows Task Summary
Details
integration_tests_gradle1-windows
Details
integration_tests_gradle2-linux Task Summary
Details
integration_tests_gradle2-linux
Details
integration_tests_gradle2-windows Task Summary
Details
integration_tests_gradle2-windows
Details
release_smoke_tests Task Summary
Details
release_smoke_tests
Details
tests_extras-linux Task Summary
Details
tests_extras-linux
Details
tests_extras-macos Task Summary
Details
tests_extras-macos
Details
tests_extras-windows Task Summary
Details
tests_extras-windows
Details
tests_framework_other-linux Task Summary
Details
tests_framework_other-linux
Details
tests_framework_other-macos Task Summary
Details
tests_framework_other-macos
Details
tests_framework_other-windows Task Summary
Details
tests_framework_other-windows
Details
tests_widgets-linux Task Summary
Details
tests_widgets-linux
Details
tests_widgets-macos Task Summary
Details
tests_widgets-macos
Details
tests_widgets-windows Task Summary
Details
tests_widgets-windows
Details
tool_coverage-linux
Details
tool_tests-linux Task Summary
Details
tool_tests-linux
Details
tool_tests-macos Task Summary
Details
tool_tests-macos
Details
tool_tests-windows Task Summary
Details
tool_tests-windows
Details
tool_tests_create-linux Task Summary
Details
tool_tests_create-linux
Details
tool_tests_create-macos Task Summary
Details
tool_tests_create-macos
Details
tool_tests_create-windows Task Summary
Details
tool_tests_create-windows
Details
tool_tests_integration-linux Task Summary
Details
tool_tests_integration-linux
Details
tool_tests_integration-macos Task Summary
Details
tool_tests_integration-macos
Details
tool_tests_integration-windows Task Summary
Details
tool_tests_integration-windows
Details
@johnsonmh johnsonmh deleted the johnsonmh:feature-chipTextColorStates branch Aug 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.