SearchBar.scrollPadding (#152635)

Pass through the missing scrollPadding parameter for SearchBar and SearchAnchor.bar.
This commit is contained in:
Justin McCandless 2024-08-01 13:56:04 -07:00 committed by GitHub
parent e08b0a56f9
commit 67a958568e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 52 additions and 5 deletions

View File

@ -184,6 +184,7 @@ class SearchAnchor extends StatefulWidget {
required SuggestionsBuilder suggestionsBuilder, required SuggestionsBuilder suggestionsBuilder,
TextInputAction? textInputAction, TextInputAction? textInputAction,
TextInputType? keyboardType, TextInputType? keyboardType,
EdgeInsets scrollPadding,
}) = _SearchAnchorWithSearchBar; }) = _SearchAnchorWithSearchBar;
/// Whether the search view grows to fill the entire screen when the /// Whether the search view grows to fill the entire screen when the
@ -1033,6 +1034,7 @@ class _SearchAnchorWithSearchBar extends SearchAnchor {
required super.suggestionsBuilder, required super.suggestionsBuilder,
super.textInputAction, super.textInputAction,
super.keyboardType, super.keyboardType,
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
}) : super( }) : super(
viewHintText: viewHintText ?? barHintText, viewHintText: viewHintText ?? barHintText,
headerHeight: viewHeaderHeight, headerHeight: viewHeaderHeight,
@ -1066,6 +1068,7 @@ class _SearchAnchorWithSearchBar extends SearchAnchor {
textCapitalization: textCapitalization, textCapitalization: textCapitalization,
textInputAction: textInputAction, textInputAction: textInputAction,
keyboardType: keyboardType, keyboardType: keyboardType,
scrollPadding: scrollPadding,
); );
} }
); );
@ -1186,6 +1189,7 @@ class SearchBar extends StatefulWidget {
this.autoFocus = false, this.autoFocus = false,
this.textInputAction, this.textInputAction,
this.keyboardType, this.keyboardType,
this.scrollPadding = const EdgeInsets.all(20.0),
}); });
/// Controls the text being edited in the search bar's text field. /// 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]. /// Defaults to the default value specified in [TextField].
final TextInputType? keyboardType; final TextInputType? keyboardType;
/// {@macro flutter.widgets.editableText.scrollPadding}
final EdgeInsets scrollPadding;
@override @override
State<SearchBar> createState() => _SearchBarState(); State<SearchBar> createState() => _SearchBarState();
} }
@ -1467,6 +1474,7 @@ class _SearchBarState extends State<SearchBar> {
textCapitalization: effectiveTextCapitalization, textCapitalization: effectiveTextCapitalization,
textInputAction: widget.textInputAction, textInputAction: widget.textInputAction,
keyboardType: widget.keyboardType, keyboardType: widget.keyboardType,
scrollPadding: widget.scrollPadding,
), ),
), ),
), ),

View File

@ -1642,12 +1642,14 @@ class EditableText extends StatefulWidget {
final Brightness keyboardAppearance; final Brightness keyboardAppearance;
/// {@template flutter.widgets.editableText.scrollPadding} /// {@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 /// When this widget receives focus and is not completely visible (for example
/// off the screen or overlapped by the keyboard) /// scrolled partially off the screen or overlapped by the keyboard), then it
/// then it will attempt to make itself visible by scrolling a surrounding [Scrollable], if one is present. /// will attempt to make itself visible by scrolling a surrounding
/// This value controls how far from the edges of a [Scrollable] the TextField will be positioned after the scroll. /// [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). /// Defaults to EdgeInsets.all(20.0).
/// {@endtemplate} /// {@endtemplate}

View File

@ -3274,6 +3274,43 @@ void main() {
expect(find.text('Item - 1'), findsOneWidget); 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 <Widget>[];
},
scrollPadding: scrollPadding,
),
),
),
);
expect(find.byType(EditableText), findsOneWidget);
final EditableText editableText = tester.widget(find.byType(EditableText));
expect(editableText.scrollPadding, scrollPadding);
});
} }
Future<void> checkSearchBarDefaults(WidgetTester tester, ColorScheme colorScheme, Material material) async { Future<void> checkSearchBarDefaults(WidgetTester tester, ColorScheme colorScheme, Material material) async {