Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix TextButton.icon breaks focus traversal and ink effect when toggling icon#176579

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
bleroux wants to merge1 commit intoflutter:master
base:master
Choose a base branch
Loading
frombleroux:fix_TextButton.icon_breaks_focus

Conversation

bleroux
Copy link
Contributor

Description

This PR changesTextButton.icon to avoid building a different widget. When a different widget is created the whole subtree is recreated which leads to various issues (Focus and A11y issues for instance).
The change is similar to#175810 which fixed the exact same problem forOutlinedButton.icon.

Related Issue

FixesTextButton.icon breaks focus traversal and ink effect when toggling icon

Tests

  • Adds 1 test

@github-actionsgithub-actionsbot added a: text inputEntering text in a text field or keyboard related problems frameworkflutter/packages/flutter repository. See also f: labels. f: material designflutter/packages/flutter/material repository. labelsOct 6, 2025
Copy link
Contributor

@gemini-code-assistgemini-code-assistbot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue whereTextButton.icon loses focus when its icon is toggled. The implementation refactors theTextButton.icon factory into a named constructor. This change prevents the widget from being rebuilt, which preserves its state, including focus. The_TextButtonWithIcon subclass is removed, and its padding logic is integrated intoTextButton. A regression test is added to verify that focus is maintained when the icon is nullified. My review includes a suggestion to update a doc comment that has become inaccurate due to these changes.

@blerouxblerouxforce-pushed thefix_TextButton.icon_breaks_focus branch from89921ce tod46cf10CompareOctober 6, 2025 14:15
@blerouxbleroux requested a review fromchunhtaiOctober 6, 2025 14:23
@bleroux
Copy link
ContributorAuthor

cc@chunhtai Assigning you for the review because the change is similar to#175810 that you reviewed recently.

@blerouxblerouxforce-pushed thefix_TextButton.icon_breaks_focus branch fromd46cf10 tod5f104bCompareOctober 6, 2025 18:19
Copy link
Contributor

@chunhtaichunhtai left a comment

Choose a reason for hiding this comment

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

LGTM, looks like it is the same for ElevatedButton and FilledButton as well. I wish we have some way to share code without exposing additional API

bleroux reacted with heart emoji
@bleroux
Copy link
ContributorAuthor

@chunhtai Are there any visual diffs in the Google testing failures? Or are those failures related to tests looking up widgets by type?
My bet it is the second case. Those tests will have to be updated similarly to the flutter gallery test updated in this PR wherefind.byType(TextButton) returns more widgets now as widgets created byTextButton.icon are now included in the result and were not before this PR.

@chunhtai
Copy link
Contributor

I saw a button that was previous disabled but becomes enabled, maybe some of the enabling or onpress callback is not wire up correctly?

@chunhtai
Copy link
Contributor

before
image
after
image

@chunhtai
Copy link
Contributor

This is their code, are we overriding the disable style somehow?

final style=        buttonStyle??TextButton.styleFrom(          foregroundColor: theme.colors.primary,          disabledForegroundColor: theme.colors.onSurfaceVariant,          iconColor: theme.colors.primary,          disabledIconColor: theme.colors.onSurfaceVariant,          textStyle: buttonSize==ButtonSize.medium? theme.textStyles.labelLarge: theme.textStyles.bodyMedium,        );returnTextButton(              onPressed: onTap!=null? () {onTap!();                    }:null,              style: style,              child:Text(label),            );

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@chunhtaichunhtaichunhtai approved these changes

+1 more reviewer

@gemini-code-assistgemini-code-assist[bot]gemini-code-assist[bot] left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
a: text inputEntering text in a text field or keyboard related problemsf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

TextButton.icon breaks focus traversal and ink effect when toggling icon
2 participants
@bleroux@chunhtai

[8]ページ先頭

©2009-2025 Movatter.jp