Skip to content

Commit 3dbab32

Browse files
authored
[material_ui] Make SearchAnchor.bar respect SearchBarThemeData padding (flutter#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.
1 parent 5309763 commit 3dbab32

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎packages/material_ui/lib/src/search_anchor.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,7 @@ class _SearchAnchorWithSearchBar extends SearchAnchor {
14221422
shape: barShape,
14231423
padding:
14241424
barPadding ??
1425+
SearchBarTheme.of(context).padding ??
14251426
const MaterialStatePropertyAll<EdgeInsets>(EdgeInsets.symmetric(horizontal: 16.0)),
14261427
leading: barLeading ?? const Icon(Icons.search),
14271428
trailing: barTrailing,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
changelog: |
2+
- Makes `SearchAnchor.bar` use `SearchBarThemeData.padding` when `barPadding` is null.
3+
version: patch

‎packages/material_ui/test/search_anchor_test.dart‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4567,6 +4567,34 @@ void main() {
45674567
expect(viewTextField.smartQuotesType, SmartQuotesType.disabled);
45684568
});
45694569

4570+
// Regression test for https://github.com/flutter/flutter/issues/185889.
4571+
testWidgets('SearchAnchor.bar respects SearchBarThemeData.padding', (WidgetTester tester) async {
4572+
const customPadding = EdgeInsets.all(32.0);
4573+
4574+
await tester.pumpWidget(
4575+
MaterialApp(
4576+
home: Scaffold(
4577+
body: SearchBarTheme(
4578+
data: const SearchBarThemeData(
4579+
padding: WidgetStatePropertyAll<EdgeInsetsGeometry>(customPadding),
4580+
),
4581+
child: SearchAnchor.bar(
4582+
suggestionsBuilder: (BuildContext context, SearchController controller) {
4583+
return <Widget>[];
4584+
},
4585+
),
4586+
),
4587+
),
4588+
),
4589+
);
4590+
4591+
final Padding paddingWidget = tester.widget<Padding>(
4592+
find.descendant(of: find.byType(SearchBar), matching: find.byType(Padding)).first,
4593+
);
4594+
4595+
expect(paddingWidget.padding, customPadding);
4596+
});
4597+
45704598
testWidgets('SearchAnchor does not crash at zero area', (WidgetTester tester) async {
45714599
tester.view.physicalSize = Size.zero;
45724600
final controller = SearchController();

0 commit comments

Comments
 (0)