Skip to content

Conversation

@rydmike
Copy link
Contributor

@rydmike rydmike commented Mar 22, 2023

FIX: SegmentedButton segments background cannot be made transparent

BEFORE

Light Dark
Screenshot 2023-03-22 at 23 16 31 Screenshot 2023-03-22 at 23 16 45

AFTER

Light Dark
Screenshot 2023-03-22 at 23 17 25 Screenshot 2023-03-22 at 23 17 39

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 22, 2023
@rydmike rydmike changed the title FIX: https://github.com/flutter/flutter/issues/123292 FIX: FIX: SegmentedButton segments background cannot be made transparent Mar 22, 2023
@rydmike rydmike changed the title FIX: FIX: SegmentedButton segments background cannot be made transparent FIX: SegmentedButton segments background cannot be made transparent Mar 22, 2023
@HansMuller HansMuller requested a review from esouthren March 23, 2023 16:13
@rydmike
Copy link
Contributor Author

rydmike commented Mar 24, 2023

@esouthren and @HansMuller, as prior art reference, the use-case and rationale for this is equivalent to the M3 mode of ListTile, that for a brief while had surface color as an opaque background. This made it cumbersome to use it e.g. in popup menus with elevation tint in M3.

ListTile was changed to use transparent background. I think @TahaTesser was involved in that change.

As stated in the issue, the M3 spec says background color of unselected segments is transparent. It is admittedly a bit vague about doing that. The illustrations show them as such, and it specifically only mentions background color of selected segments.

Current implementation of the SegmentedButton thus already returns null as background color for unselected segments, giving them no color, as the spec specifies. The unselected segments do however not become transparent, since the entire button is drawn on opaque Material. Changing it to transparent Material did not break any past tests.

By letting it use transparent Material the SegmentedButton, like ListTile can be used without issue on elevation tinted surfaces.

Making unselected segment buttons fully opaque is still possible by just giving them a color. With this FIX you can also create designs that uses segments in SegmentedButton with partially transparent background on both selected and unselected segments, with different opacities. This is currently not possible, it is a nice feature richness enhancement effect of this tiny FIX.

Copy link
Contributor

@esouthren esouthren left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for the comprehensive writeup and fix!

@TahaTesser TahaTesser requested a review from HansMuller March 27, 2023 21:17
Copy link
Member

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

LGTM! (second review to land this)

@TahaTesser
Copy link
Member

@rydmike
Can you please rebase to fix google testing?

@HansMuller
Copy link
Contributor

I've updated the PR, hopefully that will fix the Google Testing "your PR is out of date" problem

@TahaTesser TahaTesser added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 27, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 27, 2023

auto label is removed for flutter/flutter, pr: 123293, due to - The status or check suite Linux_android android_defines_test has failed. Please fix the issues identified (or deflake) before re-applying this label.

@rydmike
Copy link
Contributor Author

rydmike commented Mar 27, 2023

Sorry, 1 am here, was not online, even though I often am at this time :)
Thx for updating the PR Hans. Looks like the Linux_android android_defines_test failed, also after the update.

@HansMuller
Copy link
Contributor

I took a gamble and just restarted Linux_android android_defines_test, since it didn't appear to have anything to do with this PR.

@HansMuller
Copy link
Contributor

The failing customer test is https://github.com/macosui/macos_ui/blob/dev/test/selectors/date_picker_test.dart#L292:

| ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
| The following TestFailure was thrown running a test:
| Expected: <2>
|   Actual: <3>
|
| When the exception was thrown, this was the stack:
| #4      main.<anonymous closure>.<anonymous closure> (file:///tmp/flutter_customer_testing.macos_ui.DOFKBA/tests/test/selectors/date_picker_test.dart:292:11)
| <asynchronous suspension>
| <asynchronous suspension>
| (elided one frame from package:stack_trace)
|
| This was caught by the test expectation on the following line:
|   file:///tmp/flutter_customer_testing.macos_ui.DOFKBA/tests/test/selectors/date_picker_test.dart line 292
| The test description was:
|   Can change the month by clicking the left and right calendar view controls
| ════════════════════════════════════════════════════════════════════════════════════════════════════

@HansMuller HansMuller added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 29, 2023
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 30, 2023
@auto-submit
Copy link
Contributor

auto-submit bot commented Mar 30, 2023

auto label is removed for flutter/flutter, pr: 123293, due to - The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

@HansMuller
Copy link
Contributor

There are a small number of internal golden image test failures (internal google link cl/520561370)

Expected:
Screenshot 2023-03-30 at 1 07 49 PM

Actual:
Screenshot 2023-03-30 at 1 07 57 PM

The change looks OK to me (the button backgrounds are supposed to be transparent).

@esouthren do the diffs look OK to you?

@rydmike
Copy link
Contributor Author

rydmike commented Mar 30, 2023

The shown images are as can be seen different. The expected one has a bit of background color and actual one does not, since it is transparent. This would be the case if some color was used on SegmentedButton's underlying canvas Material by default in the expected golden result.

@esouthren
Copy link
Contributor

There are a small number of internal golden image test failures (internal google link cl/520561370)

The change looks OK to me (the button backgrounds are supposed to be transparent).

@esouthren do the diffs look OK to you?

LGTM, thanks

@HansMuller
Copy link
Contributor

@XilaiZhang - this PR is being held up by the same issue as #123294: #123294 (comment). What do we need to do to see the Google Testing results?

@XilaiZhang
Copy link
Contributor

temp workaround: the test failures are at test/521658605 and the cl is cl/521658605

Thanks for reporting the issue! will keep track of it in b/260764527

@HansMuller HansMuller merged commit be5a842 into flutter:master Apr 4, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 5, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 5, 2023
exaby73 pushed a commit to NevercodeHQ/flutter that referenced this pull request Apr 17, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
@rydmike rydmike deleted the segemented_button_use_transparent_material branch November 16, 2025 12:47
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.

[Material3 spec] SegmentedButton segments background cannot be made transparent

5 participants