Skip to content

Conversation

@bleroux
Copy link
Contributor

@bleroux bleroux commented Nov 18, 2024

Description

This PR fixes InkWell overlay colors resolution.
The InkWell overlay color is resolved when the InkWell is either focused, hovered , and/or pressed.
This resolution happens at two places:

  • first when the highlight is created.
  • then on each build, using the inner function named getHighlightColorForType.
    This second resolution should be aware of other current states (such as selected) as it might impact the color resolution.

For instance, several Material styles have colors resolution define similarly to:

MaterialStateProperty<Color?>? get dayOverlayColor =>
MaterialStateProperty.resolveWith((Set<MaterialState> states) {
if (states.contains(MaterialState.selected)) {
if (states.contains(MaterialState.pressed)) {
return _colors.onPrimary.withOpacity(0.1);
}
if (states.contains(MaterialState.hovered)) {
return _colors.onPrimary.withOpacity(0.08);
}
if (states.contains(MaterialState.focused)) {
return _colors.onPrimary.withOpacity(0.1);
}
} else {
if (states.contains(MaterialState.pressed)) {
return _colors.onSurfaceVariant.withOpacity(0.1);
}
if (states.contains(MaterialState.hovered)) {
return _colors.onSurfaceVariant.withOpacity(0.08);
}
if (states.contains(MaterialState.focused)) {
return _colors.onSurfaceVariant.withOpacity(0.1);
}
}
return null;
});

Related Issue

Fixes InkWell overlay colors aren't applied on MaterialState.selected state
First step for Date picker overlay colors aren't applied on MaterialState.selected state.

Tests

Adds 3 tests.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Nov 18, 2024
@bleroux bleroux force-pushed the fix_ink_well_overlay_color_resolution_ignores_selected_state branch from 6c2fe5e to 0612cec Compare November 18, 2024 15:11
@bleroux bleroux requested a review from justinmc November 18, 2024 15:38
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM with a few typo nits in the docs 👍

const Set<MaterialState> highlightableStates = <MaterialState>{MaterialState.focused, MaterialState.hovered, MaterialState.pressed};
final Set<MaterialState> nonHighlightableStates = statesController.value.difference(highlightableStates);
// Each highlightable states will be resolved separatly to get the corresponding color.
// For this resolution to be correct, The non-highlightable states should be preserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

"The" => "the"

final ThemeData theme = Theme.of(context);
const Set<MaterialState> highlightableStates = <MaterialState>{MaterialState.focused, MaterialState.hovered, MaterialState.pressed};
final Set<MaterialState> nonHighlightableStates = statesController.value.difference(highlightableStates);
// Each highlightable states will be resolved separatly to get the corresponding color.
Copy link
Contributor

Choose a reason for hiding this comment

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

"states" => "state"
"separatly" => "separately"

import '../widgets/semantics_tester.dart';

void main() {
RenderObject getInkFeatures(WidgetTester tester) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call splitting this out.

final Set<MaterialState> nonHighlightableStates = statesController.value.difference(highlightableStates);
// Each highlightable states will be resolved separatly to get the corresponding color.
// For this resolution to be correct, The non-highlightable states should be preserved.
final Set<MaterialState> pressed = <MaterialState>{...nonHighlightableStates, MaterialState.pressed};
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 kind of tricky, I hope we don't make this same kind of mistake elsewhere. I guess it's probably rare to speculatively resolve a color like this, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hope we don't make this same kind of mistake elsewher

I looked at various places where the color are resolved. I think this one is somewhat particular because most of InkWell logic was written way before widget state controllers were introduced. For instance the getHighlightColorForType function was added in #31438 and then was updated and moved later.
This logic can probably be simplified, but because this is a core widget I tried to fix the issue without taking risk.

@bleroux
Copy link
Contributor Author

bleroux commented Nov 18, 2024

@justinmc Thanks for the review, especially for catching these typos. 🙏

Let see how it goes with Google testing because this might break some golden (if there are golden capturing hovering, focused or pressed state). For instance, with this fix hovered color for some widgets which have a selected state (such as IconButton) is slightly different (the change is slight because the defaults colors are very close but this could be noticed when comparing screenshots.
For instance, here are screenshots of an icon button created from IconButton.filledTonal constructor when hovered:

Before After
Capture d’écran 2024-11-18 à 11 55 48 Capture d’écran 2024-11-18 à 11 56 08

@bleroux bleroux force-pushed the fix_ink_well_overlay_color_resolution_ignores_selected_state branch from 0612cec to 9ff6c2f Compare November 19, 2024 08:22
@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2024
@auto-submit auto-submit bot added this pull request to the merge queue Nov 19, 2024
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 19, 2024
Merged via the queue into flutter:master with commit 043c59b Nov 19, 2024
79 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 19, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 19, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 19, 2024
flutter/flutter@b3818f6...8536b96

2024-11-19 [email protected] Terminate `flutter test` when no longer needed in integration test. (flutter/flutter#159117)
2024-11-19 [email protected] Terminate the test device if the `flutter` tool is signal-killed. (flutter/flutter#159115)
2024-11-19 [email protected] Roll Packages from c1eabf5 to fc4adc7 (10 revisions) (flutter/flutter#159143)
2024-11-19 [email protected] Deflake api 35 emulator tests by updating emulator definitions version to latest available from chrome infra (flutter/flutter#158017)
2024-11-19 [email protected] Roll Flutter Engine from b6723e33b858 to cff1e751f853 (1 revision) (flutter/flutter#159141)
2024-11-19 [email protected] Fix InkWell overlayColor resolution ignores selected state (flutter/flutter#159072)
2024-11-19 [email protected] Roll Flutter Engine from 983b7b85d122 to b6723e33b858 (3 revisions) (flutter/flutter#159134)
2024-11-19 [email protected] Roll Flutter Engine from c1b0e18a70b3 to 983b7b85d122 (2 revisions) (flutter/flutter#159124)
2024-11-19 [email protected] Roll Flutter Engine from 878f593802e1 to c1b0e18a70b3 (13 revisions) (flutter/flutter#159118)
2024-11-19 [email protected] [SwiftPM] Move where the migration checks feature flags (flutter/flutter#159110)
2024-11-18 [email protected] Plumbs `scrollBehavior` into `SelectableText` so that the scrollbar may be hidden (flutter/flutter#158887)
2024-11-18 [email protected] Add a tag and assert some state in FlutterTestDriver tests. (flutter/flutter#159099)
2024-11-18 49699333+dependabot[bot]@users.noreply.github.com Bump codecov/codecov-action from 4.6.0 to 5.0.2 in the all-github-actions group (flutter/flutter#159104)
2024-11-18 [email protected] Add `@protected` to public `State` method overrides (flutter/flutter#157313)
2024-11-18 [email protected] Roll Flutter Engine from 9686de154114 to 878f593802e1 (5 revisions) (flutter/flutter#159097)
2024-11-18 [email protected] Fix flaky failure related to core_device_list.json not being found (flutter/flutter#158946)
2024-11-18 [email protected] Prettier merge_queue.md (flutter/flutter#158969)
2024-11-18 [email protected] Define and use `flutterBin` consistently across `integration.shard`. (flutter/flutter#159007)
2024-11-18 [email protected] No longer download `android-x86-jit-release`. (flutter/flutter#159011)
2024-11-18 [email protected] Roll Flutter Engine from e1f4e7d9bfc4 to 9686de154114 (1 revision) (flutter/flutter#159082)
2024-11-18 [email protected] Roll Flutter Engine from f365c9f5dce3 to e1f4e7d9bfc4 (4 revisions) (flutter/flutter#159078)
2024-11-18 [email protected] Roll Packages from b164be3 to c1eabf5 (6 revisions) (flutter/flutter#159077)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@bleroux bleroux deleted the fix_ink_well_overlay_color_resolution_ignores_selected_state branch November 19, 2024 18:38
github-merge-queue bot pushed a commit that referenced this pull request Nov 25, 2024
)

## Description

This PR fixes the DatePicker overlay colors for the selected days.
Before this PR, overlays were obscured by the selected day backgound.
This fix simply replaces a DecoratedBox with an Ink to make the overlays
visible.
Combined with #159072 which fixes
InkWell overlay color resolution related to the selected state, this PR
fixes [Date picker overlay colors aren't applied on
MaterialState.selected
state](#130586).

Before, no overlay visible for the selected day when hovered, focused,
or pressed:


https://github.com/user-attachments/assets/944d5035-68b2-40da-b606-3e8795229767

After, overlay is visible for the selected day when hovered, focused, or
pressed (color change is slight as defined with M3 defaults):


https://github.com/user-attachments/assets/2627955b-f45a-465f-8eb0-21955ccd8c3e


## Related Issue

Fixes [Date picker overlay colors aren't applied on
MaterialState.selected
state](#130586).

## Tests

Adds 12 tests.
Updates several existing tests (those tests were looking for a
`DecoratedBox`, make them look for an `Ink`).
github-merge-queue bot pushed a commit that referenced this pull request Nov 28, 2024
#159583)

Reverts #159203 because it
depends on #159072 which was
flagged as a perf regression in
#159337.

Reverting both PRs to see if the perf regression was really related to
this change or was impacted by another change. See
#159337 (comment)
for context.
bleroux added a commit to NevercodeHQ/flutter that referenced this pull request Nov 28, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 28, 2024
…159072) (#159589)

Reverts #159072 which was flagged
as a perf regression in
#159337.

Reverting to see if the perf regression was really related to this
change or was impacted by another change. See
#159337 (comment)
for context.
github-merge-queue bot pushed a commit that referenced this pull request Dec 4, 2024
…59784)

Reland #159072 without change.
The initial PR was flagged for a non-related perf regression, see
#159337 (comment)

Fixes #159063
@reidbaker reidbaker mentioned this pull request Dec 13, 2024
11 tasks
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
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.

InkWell overlay colors aren't applied on MaterialState.selected state

2 participants