Skip to content

Make SearchAnchor.bar respect SearchBarTheme padding - #186666

Closed
MarlonJD wants to merge 6 commits into
flutter:masterfrom
MarlonJD:search-anchor-theme-data
Closed

MarlonJD wants to merge 6 commits into
flutter:masterfrom
MarlonJD:search-anchor-theme-data

Conversation

@MarlonJD

Copy link
Copy Markdown
Contributor

Part of #185889.

SearchAnchor.bar was passing its own hard-coded default padding to the inner SearchBar whenever barPadding was null. That prevented SearchBar from falling back to SearchBarThemeData.padding.

This removes that hard-coded barPadding fallback so the normal SearchBar resolution order applies:

  • explicit barPadding
  • SearchBarThemeData.padding
  • default SearchBar padding

Regression tests cover both themed padding and explicit barPadding overriding the theme.

Note: SearchBarThemeData does not currently expose a leading property, so this PR addresses the padding behavior from the issue's repro.

Validation:

  • dart analyze packages/flutter/lib/src/material/search_anchor.dart packages/flutter/test/material/search_anchor_test.dart
  • flutter test packages/flutter/test/material/search_anchor_test.dart

@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 18, 2026

@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 modifies SearchAnchor.bar to allow the internal SearchBar to inherit padding from SearchBarThemeData by removing a hardcoded default value. New tests were added to verify that theme padding is correctly applied and can be overridden by the barPadding property. Review feedback suggests using const for WidgetStatePropertyAll instances in the tests for performance and consistency, and adding comments to explain assertions that expect multiple widgets to improve maintainability.

@MarlonJD

Copy link
Copy Markdown
Contributor Author

Pushed 1dc34743c63 to address the remaining readability feedback by documenting why the tests expect two SearchBar widgets. Re-verified locally with dart analyze packages/flutter/lib/src/material/search_anchor.dart packages/flutter/test/material/search_anchor_test.dart and ./bin/flutter test packages/flutter/test/material/search_anchor_test.dart.

@dkwingsmt
dkwingsmt requested review from QuncCccccc and dkwingsmt and removed request for dkwingsmt May 20, 2026 18:30

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

Thanks a lot for your contribution! Seems the change doesn't really fix the issue, and we have another PR #186037 fixing the same issue, so I'm closing this PR for now:)

padding:
barPadding ??
const MaterialStatePropertyAll<EdgeInsets>(EdgeInsets.symmetric(horizontal: 16.0)),
padding: barPadding,

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.

This seems not a correct fix since the theme padding is still not respected and we removed the default value.

(Widget widget) => widget is Padding && widget.padding == themePadding,
),
),
findsNWidgets(searchBarsForAnchorAndView),

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.

This test should check whether themePaddingProperty is respected.

@QuncCccccc QuncCccccc closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants