Skip to content

Conversation

@huycozy
Copy link
Member

@huycozy huycozy commented Apr 26, 2025

Fix #70294

Description

The bug is about the previously selected DropdownMenuItem isn't highlighted on mobile while it works on Web and desktop. The reason is that FocusManager.instance.highlightMode has fallen to FocusHighlightMode.touch on mobile by default (or touch device without mouse in general):

final bool inTraditionalMode = switch (FocusManager.instance.highlightMode) {
FocusHighlightMode.touch => false,
FocusHighlightMode.traditional => true,
};

static FocusHighlightMode get _defaultModeForPlatform {
// Assume that if we're on one of the mobile platforms, and there's no mouse
// connected, that the initial interaction will be touch-based, and that
// it's traditional mouse and keyboard on all other platforms.
//
// This only affects the initial value: the ongoing value is updated to a
// known correct value as soon as any pointer/keyboard events are received.
switch (defaultTargetPlatform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
case TargetPlatform.iOS:
if (WidgetsBinding.instance.mouseTracker.mouseIsConnected) {
return FocusHighlightMode.traditional;
}
return FocusHighlightMode.touch;
case TargetPlatform.linux:
case TargetPlatform.macOS:
case TargetPlatform.windows:
return FocusHighlightMode.traditional;

/// If [highlightMode] returns [FocusHighlightMode.touch], then widgets should
/// not draw their focus highlight unless they perform text entry.
///
/// If [highlightMode] returns [FocusHighlightMode.traditional], then widgets should
/// draw their focus highlight whenever they are focused.
// Don't want to set _highlightMode here, since it's possible for the target
// platform to change (especially in tests).
FocusHighlightMode get highlightMode => _highlightManager.highlightMode;

We actually can work around this by setting FocusManager.instance.highlightStrategy to FocusHighlightStrategy.alwaysTraditional, see #70442 (comment). Nevertheless, this approach will may affect the entire scope of the app, potentially resulting in unforeseen behavior for other widgets. 

In this PR, I propose a straightforward solution that utilizes an ancestor widget (Ink) to manage the color state corresponding to InkWell.overlayColor.

Demo the fix

Screen.Recording.2025-04-24.at.15.16.37.mov

Pre-launch Checklist

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

@huycozy huycozy self-assigned this Apr 26, 2025
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Apr 26, 2025
@huycozy huycozy force-pushed the fix-dropdownbutton-selected-state-color-70294 branch 4 times, most recently from 37c4ec1 to b95a68a Compare April 28, 2025 11:07
@huycozy huycozy marked this pull request as ready for review April 28, 2025 14:27
@huycozy huycozy requested review from bleroux and justinmc April 29, 2025 07:50
@huycozy huycozy force-pushed the fix-dropdownbutton-selected-state-color-70294 branch from b95a68a to a06e8fa Compare April 29, 2025 09:41
@huycozy huycozy requested a review from bleroux May 5, 2025 02:18
Copy link
Contributor

@bleroux bleroux left a comment

Choose a reason for hiding this comment

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

LGTM to trigger Google tests

@huycozy huycozy force-pushed the fix-dropdownbutton-selected-state-color-70294 branch 2 times, most recently from 4702e1a to 3416529 Compare May 6, 2025 03:45
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 👍

Sorry I missed this PR for so long!

@justinmc
Copy link
Contributor

justinmc commented May 9, 2025

The Google tests did complete and there were failures, but they are all expected. Something might be wrong with the infrastructure since I don't see it turning green. @huycozy If it still says "pending" on Monday then maybe push another rebase and ping me?

@huycozy huycozy force-pushed the fix-dropdownbutton-selected-state-color-70294 branch from 3416529 to d2c6df3 Compare May 12, 2025 03:30
@huycozy huycozy added the autosubmit Merge PR when tree becomes green via auto submit App label May 12, 2025
@auto-submit auto-submit bot added this pull request to the merge queue May 12, 2025
Merged via the queue into flutter:master with commit 1ca93de May 12, 2025
75 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label May 12, 2025
@huycozy huycozy deleted the fix-dropdownbutton-selected-state-color-70294 branch May 12, 2025 10:49
auto-submit bot pushed a commit to flutter/packages that referenced this pull request May 12, 2025
flutter/flutter@992ad74...54de32d

2025-05-12 [email protected] Update hello_world example to current layout flutter create uses (flutter/flutter#168571)
2025-05-12 [email protected] Roll Skia from cb1646ca59db to 9f9e1f37917e (1 revision) (flutter/flutter#168656)
2025-05-12 [email protected] Fix Selected DropdownMenuItem isn't highlighted on mobile (flutter/flutter#167874)
2025-05-12 [email protected] Api docs: Add Widget of the Week video to DropdownMenu (flutter/flutter#168254)
2025-05-12 [email protected] Bumping Framework Default TargetSdk to 36 (flutter/flutter#168577)
2025-05-11 [email protected] Roll Fuchsia Linux SDK from VIG5-P9wwXgQkCkeX... to 6vjKe0bfYDVaECqBL... (flutter/flutter#168646)
2025-05-11 [email protected] Roll Skia from 0feee17aeaca to cb1646ca59db (1 revision) (flutter/flutter#168642)

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] 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
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
…#9243)

flutter/flutter@992ad74...54de32d

2025-05-12 [email protected] Update hello_world example to current layout flutter create uses (flutter/flutter#168571)
2025-05-12 [email protected] Roll Skia from cb1646ca59db to 9f9e1f37917e (1 revision) (flutter/flutter#168656)
2025-05-12 [email protected] Fix Selected DropdownMenuItem isn't highlighted on mobile (flutter/flutter#167874)
2025-05-12 [email protected] Api docs: Add Widget of the Week video to DropdownMenu (flutter/flutter#168254)
2025-05-12 [email protected] Bumping Framework Default TargetSdk to 36 (flutter/flutter#168577)
2025-05-11 [email protected] Roll Fuchsia Linux SDK from VIG5-P9wwXgQkCkeX... to 6vjKe0bfYDVaECqBL... (flutter/flutter#168646)
2025-05-11 [email protected] Roll Skia from 0feee17aeaca to cb1646ca59db (1 revision) (flutter/flutter#168642)

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] 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
Ortes pushed a commit to Ortes/packages that referenced this pull request Jun 25, 2025
…#9243)

flutter/flutter@992ad74...54de32d

2025-05-12 [email protected] Update hello_world example to current layout flutter create uses (flutter/flutter#168571)
2025-05-12 [email protected] Roll Skia from cb1646ca59db to 9f9e1f37917e (1 revision) (flutter/flutter#168656)
2025-05-12 [email protected] Fix Selected DropdownMenuItem isn't highlighted on mobile (flutter/flutter#167874)
2025-05-12 [email protected] Api docs: Add Widget of the Week video to DropdownMenu (flutter/flutter#168254)
2025-05-12 [email protected] Bumping Framework Default TargetSdk to 36 (flutter/flutter#168577)
2025-05-11 [email protected] Roll Fuchsia Linux SDK from VIG5-P9wwXgQkCkeX... to 6vjKe0bfYDVaECqBL... (flutter/flutter#168646)
2025-05-11 [email protected] Roll Skia from 0feee17aeaca to cb1646ca59db (1 revision) (flutter/flutter#168642)

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

[mobile] Selected DropdownMenuItem isn't highlighted on mobile only

3 participants