Skip to content

Fix SearchAnchor.bar to respect SearchBarThemeData padding - #186037

Draft
CoderBoxer wants to merge 3 commits into
flutter:masterfrom
CoderBoxer:fix-search-anchor-theme
Draft

CoderBoxer wants to merge 3 commits into
flutter:masterfrom
CoderBoxer:fix-search-anchor-theme

Conversation

@CoderBoxer

Copy link
Copy Markdown

Description

This PR fixes an issue where SearchAnchor.bar was bypassing SearchBarThemeData.padding and falling back directly to a hardcoded default of 16.0.

I added SearchBarTheme.of(context).padding to the resolution chain in _SearchAnchorWithSearchBar so that it correctly inherits the global theme properties before falling back to the defaults.

(Note: barLeading retains its existing fallback behavior since SearchBarThemeData does not possess a leading property).

Related Issue

Fixes #185889

Tests

  • Added a regression test in search_anchor_test.dart to verify that SearchAnchor.bar properly respects the SearchBarThemeData.padding property.

@github-actions github-actions Bot added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels May 5, 2026
@google-cla

google-cla Bot commented May 5, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 updates SearchAnchor.bar to respect SearchBarThemeData.padding and adds a regression test. The review feedback suggests refactoring the test to verify the padding property on the SearchBar widget directly, which improves test robustness by avoiding reliance on internal implementation details.

Comment on lines +4405 to +4409
final Padding paddingWidget = tester.widget<Padding>(
find.descendant(of: find.byType(SearchBar), matching: find.byType(Padding)).first,
);

expect(paddingWidget.padding, customPadding);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Instead of searching for a descendant Padding widget, which is an implementation detail of SearchBar, it is more robust to verify the padding property on the SearchBar widget itself. This ensures the test is directly checking the property passed to the widget rather than relying on the internal widget tree structure.

Suggested change
final Padding paddingWidget = tester.widget<Padding>(
find.descendant(of: find.byType(SearchBar), matching: find.byType(Padding)).first,
);
expect(paddingWidget.padding, customPadding);
final SearchBar searchBar = tester.widget<SearchBar>(find.byType(SearchBar));
expect(searchBar.padding?.resolve(<WidgetState>{}), customPadding);
References
  1. Assess whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

@dkwingsmt
dkwingsmt self-requested a review May 6, 2026 18:06

@QuncCccccc QuncCccccc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for your contribution!

@dkwingsmt dkwingsmt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you for finding it!

@dkwingsmt dkwingsmt added the CICD Run CI/CD label May 27, 2026
@dkwingsmt

Copy link
Copy Markdown
Contributor

There's analyzer issues. Can you address it?

@github-actions github-actions Bot removed the CICD Run CI/CD label May 29, 2026
@CoderBoxer

Copy link
Copy Markdown
Author

There's analyzer issues. Can you address it?

Hi @dkwingsmt, I merged the latest upstream/master into the branch and ran the analyzer locally. It returned 'No issues found!', so the branch is synced and pushed. Let me know if the CI still complains!

@CoderBoxer

Copy link
Copy Markdown
Author

Hey @dkwingsmt , the CI failed on the internal 'Flutter Roll on Borg' step, and I don't have access to view those internal logs. Could you take a quick look to see what broke when you have a moment?

@dkwingsmt dkwingsmt added the CICD Run CI/CD label Jun 3, 2026
@dkwingsmt

Copy link
Copy Markdown
Contributor

@CoderBoxer I'll take care of the merging process and I'll let you know if anything's worth your notice. Thank!

@dkwingsmt
dkwingsmt self-requested a review June 3, 2026 18:30

@dkwingsmt dkwingsmt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-LGTM

@dkwingsmt

Copy link
Copy Markdown
Contributor

Thanks for your contribution! This PR has reached completion, however we're not able to merge this PR for the moment due to the Material/Cupertino code freeze (#184093). As soon as the decoupling is complete, we will post a way to port this PR to the new packages to land. In the meantime, I'll convert this PR to a draft and apply a label so that we can quickly find it when the freeze is lifted.

@dkwingsmt
dkwingsmt marked this pull request as draft June 10, 2026 18:06
@dkwingsmt dkwingsmt added the waiting for code freeze This PR is waiting for a code freeze to resolve. label Jun 10, 2026
@Piinks Piinks added the Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. label Jun 24, 2026
@Piinks

Piinks commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

I've marked this PR as not ready to port to flutter/packages yet.
We'll provide instructions to move this change over to material_ui/cupertino_ui once ready to receive PRs. Thank you!

@CoderBoxer

Copy link
Copy Markdown
Author

Understood, thanks for the heads up @Piinks I'll leave this as-is and wait for the porting instructions once the decoupling is complete

@dkwingsmt

Copy link
Copy Markdown
Contributor

If you would like to return to this, material_ui and cupertino_ui are now accepting contributions. :)
Guidance and instructions for easily porting over can be found in #188444. Thank you for the contribution and for waiting!

@dkwingsmt dkwingsmt removed the Decoupling: Not ready to port yet Instructions will be provided when this is ready to move to flutter/packages. label Sep 24, 2026
@dkwingsmt dkwingsmt added the Decoupling: Port to flutter/packages This PR is ready to be ported to flutter/packages. We will provide instructions to do so. label Sep 24, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 5, 2026
#13360)

Fixes flutter/flutter#185889
Ports flutter/flutter#186037. Part of flutter/flutter#188444.

Makes `SearchAnchor.bar` use `SearchBarThemeData.padding` when `barPadding` is null.

cc @CoderBoxer

I used AI assistance to port the approved fix.

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD Decoupling: Port to flutter/packages This PR is ready to be ported to flutter/packages. We will provide instructions to do so. framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages waiting for code freeze This PR is waiting for a code freeze to resolve.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SearchAnchor.bar does not respect SearchBarThemeData.padding and SearchBarThemeData.leading

4 participants