diff --git a/packages/flutter/lib/src/material/search_anchor.dart b/packages/flutter/lib/src/material/search_anchor.dart index 4b876d2888..80ed77fc8a 100644 --- a/packages/flutter/lib/src/material/search_anchor.dart +++ b/packages/flutter/lib/src/material/search_anchor.dart @@ -184,6 +184,7 @@ class SearchAnchor extends StatefulWidget { required SuggestionsBuilder suggestionsBuilder, TextInputAction? textInputAction, TextInputType? keyboardType, + EdgeInsets scrollPadding, }) = _SearchAnchorWithSearchBar; /// Whether the search view grows to fill the entire screen when the @@ -1033,6 +1034,7 @@ class _SearchAnchorWithSearchBar extends SearchAnchor { required super.suggestionsBuilder, super.textInputAction, super.keyboardType, + EdgeInsets scrollPadding = const EdgeInsets.all(20.0), }) : super( viewHintText: viewHintText ?? barHintText, headerHeight: viewHeaderHeight, @@ -1066,6 +1068,7 @@ class _SearchAnchorWithSearchBar extends SearchAnchor { textCapitalization: textCapitalization, textInputAction: textInputAction, keyboardType: keyboardType, + scrollPadding: scrollPadding, ); } ); @@ -1186,6 +1189,7 @@ class SearchBar extends StatefulWidget { this.autoFocus = false, this.textInputAction, this.keyboardType, + this.scrollPadding = const EdgeInsets.all(20.0), }); /// Controls the text being edited in the search bar's text field. @@ -1327,6 +1331,9 @@ class SearchBar extends StatefulWidget { /// Defaults to the default value specified in [TextField]. final TextInputType? keyboardType; + /// {@macro flutter.widgets.editableText.scrollPadding} + final EdgeInsets scrollPadding; + @override State createState() => _SearchBarState(); } @@ -1467,6 +1474,7 @@ class _SearchBarState extends State { textCapitalization: effectiveTextCapitalization, textInputAction: widget.textInputAction, keyboardType: widget.keyboardType, + scrollPadding: widget.scrollPadding, ), ), ), diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 2cbd61931c..1fc202c9c0 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -1642,12 +1642,14 @@ class EditableText extends StatefulWidget { final Brightness keyboardAppearance; /// {@template flutter.widgets.editableText.scrollPadding} - /// Configures padding to edges surrounding a [Scrollable] when the Textfield scrolls into view. + /// Configures the padding for the edges surrounding a [Scrollable] when the + /// text field scrolls into view. /// - /// When this widget receives focus and is not completely visible (for example scrolled partially - /// off the screen or overlapped by the keyboard) - /// then it will attempt to make itself visible by scrolling a surrounding [Scrollable], if one is present. - /// This value controls how far from the edges of a [Scrollable] the TextField will be positioned after the scroll. + /// When this widget receives focus and is not completely visible (for example + /// scrolled partially off the screen or overlapped by the keyboard), then it + /// will attempt to make itself visible by scrolling a surrounding + /// [Scrollable], if one is present. This value controls how far from the + /// edges of a [Scrollable] the TextField will be positioned after the scroll. /// /// Defaults to EdgeInsets.all(20.0). /// {@endtemplate} diff --git a/packages/flutter/test/material/search_anchor_test.dart b/packages/flutter/test/material/search_anchor_test.dart index e7c8465889..4d66a2a869 100644 --- a/packages/flutter/test/material/search_anchor_test.dart +++ b/packages/flutter/test/material/search_anchor_test.dart @@ -3274,6 +3274,43 @@ void main() { expect(find.text('Item - 1'), findsOneWidget); }); + + testWidgets('SearchBar.scrollPadding is passed through to EditableText', (WidgetTester tester) async { + const EdgeInsets scrollPadding = EdgeInsets.zero; + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: SearchBar( + scrollPadding: scrollPadding, + ), + ), + ), + ); + + expect(find.byType(EditableText), findsOneWidget); + final EditableText editableText = tester.widget(find.byType(EditableText)); + expect(editableText.scrollPadding, scrollPadding); + }); + + testWidgets('SearchAnchor.bar.scrollPadding is passed through to EditableText', (WidgetTester tester) async { + const EdgeInsets scrollPadding = EdgeInsets.zero; + await tester.pumpWidget( + MaterialApp( + home: Material( + child: SearchAnchor.bar( + suggestionsBuilder: (BuildContext context, SearchController controller) { + return []; + }, + scrollPadding: scrollPadding, + ), + ), + ), + ); + + expect(find.byType(EditableText), findsOneWidget); + final EditableText editableText = tester.widget(find.byType(EditableText)); + expect(editableText.scrollPadding, scrollPadding); + }); } Future checkSearchBarDefaults(WidgetTester tester, ColorScheme colorScheme, Material material) async {