Skip to content

Conversation

@shihaohong
Copy link
Contributor

@shihaohong shihaohong commented Aug 19, 2019

Description

Allows developers to apply a TextStyle to the ToggleButtons through the ToggleButtons.textStyle or the ToggleButtonsTheme.textStyle properties. TextStyle.color is ignored to preserve the active/selected/disabled color states.

cc/ @lisa-liao

Code snippet (note that color is specified)

Screen Shot 2019-08-19 at 10 32 06 AM

Result (note that color is ignored)

Screen Shot 2019-08-19 at 10 32 10 AM

Related Issues

Fixes #38661

Tests

I added the following tests:

  • A test to verify the default text styles
  • A test to verify custom ToggleButtons.textStyle is applied and that color is ignored
  • A test to verify custom ToggleButtonsTheme.textStyle is applied and that color is ignored

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.

@shihaohong shihaohong added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Aug 19, 2019
Copy link
Contributor

@willlarche willlarche left a comment

Choose a reason for hiding this comment

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

Thank you!

this.borderWidth,
});

/// The [TextStyle] to apply to any text that appears in this button.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is really the default text style for the ToggleButtons' [children], since a ToggleButtons' child like Text('foo', style: bar), still wins the text style.

);

TextStyle textStyle;
textStyle = tester.firstWidget<DefaultTextStyle>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is "firstWidget" really needed here (and elsewhere)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes -- There are two Material widgets in this test -- The one explicitly instantiated and another one by RawMaterialButton, which is used to create each toggle button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Discussed offline and updated these finders to be more specific and easier to read

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

@shihaohong shihaohong merged commit b7abf56 into flutter:master Aug 20, 2019
@shihaohong shihaohong deleted the toggle-button-text-style branch September 10, 2019 16:20
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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.

Add ToggleButtons.textStyle property

4 participants