mirror of
https://github.com/flutter/flutter
synced 2024-10-14 04:02:56 +00:00
Add searchFieldStyle (#54674)
This commit is contained in:
parent
cf0fcd4536
commit
f37a91a7bf
|
@ -119,6 +119,7 @@ abstract class SearchDelegate<T> {
|
|||
/// {@end-tool}
|
||||
SearchDelegate({
|
||||
this.searchFieldLabel,
|
||||
this.searchFieldStyle,
|
||||
this.keyboardType,
|
||||
this.textInputAction = TextInputAction.search,
|
||||
});
|
||||
|
@ -264,6 +265,11 @@ abstract class SearchDelegate<T> {
|
|||
/// If this value is set to null, the value of MaterialLocalizations.of(context).searchFieldLabel will be used instead.
|
||||
final String searchFieldLabel;
|
||||
|
||||
/// The style of the [searchFieldLabel].
|
||||
///
|
||||
/// If this value is set to null, the value of the ambient [Theme]'s [ThemeData.inputDecorationTheme.hintStyle] will be used instead.
|
||||
final TextStyle searchFieldStyle;
|
||||
|
||||
/// The type of action button to use for the keyboard.
|
||||
///
|
||||
/// Defaults to the default value specified in [TextField].
|
||||
|
@ -315,7 +321,6 @@ enum _SearchBody {
|
|||
results,
|
||||
}
|
||||
|
||||
|
||||
class _SearchPageRoute<T> extends PageRoute<T> {
|
||||
_SearchPageRoute({
|
||||
@required this.delegate,
|
||||
|
@ -469,6 +474,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
|
|||
final ThemeData theme = widget.delegate.appBarTheme(context);
|
||||
final String searchFieldLabel = widget.delegate.searchFieldLabel
|
||||
?? MaterialLocalizations.of(context).searchFieldLabel;
|
||||
final TextStyle searchFieldStyle = widget.delegate.searchFieldStyle
|
||||
?? theme.inputDecorationTheme.hintStyle;
|
||||
Widget body;
|
||||
switch(widget.delegate._currentBody) {
|
||||
case _SearchBody.suggestions:
|
||||
|
@ -521,7 +528,7 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
|
|||
decoration: InputDecoration(
|
||||
border: InputBorder.none,
|
||||
hintText: searchFieldLabel,
|
||||
hintStyle: theme.inputDecorationTheme.hintStyle,
|
||||
hintStyle: searchFieldStyle,
|
||||
),
|
||||
),
|
||||
actions: widget.delegate.buildActions(context),
|
||||
|
|
|
@ -509,6 +509,23 @@ void main() {
|
|||
expect(find.text(searchHint), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Custom searchFieldStyle value', (WidgetTester tester) async {
|
||||
const TextStyle searchStyle = TextStyle(color: Colors.red, fontSize: 3);
|
||||
|
||||
final _TestSearchDelegate delegate = _TestSearchDelegate(searchFieldStyle: searchStyle);
|
||||
|
||||
await tester.pumpWidget(
|
||||
TestHomePage(
|
||||
delegate: delegate,
|
||||
));
|
||||
await tester.tap(find.byTooltip('Search'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final TextField textField = tester.widget<TextField>(find.byType(TextField));
|
||||
final TextStyle hintStyle = textField.decoration.hintStyle;
|
||||
expect(hintStyle, delegate.searchFieldStyle);
|
||||
});
|
||||
|
||||
testWidgets('keyboard show search button by default', (WidgetTester tester) async {
|
||||
final _TestSearchDelegate delegate = _TestSearchDelegate();
|
||||
|
||||
|
@ -697,9 +714,10 @@ class _TestSearchDelegate extends SearchDelegate<String> {
|
|||
this.suggestions = 'Suggestions',
|
||||
this.result = 'Result',
|
||||
this.actions = const <Widget>[],
|
||||
TextStyle searchFieldStyle,
|
||||
String searchHint,
|
||||
TextInputAction textInputAction = TextInputAction.search,
|
||||
}) : super(searchFieldLabel: searchHint, textInputAction: textInputAction);
|
||||
}) : super(searchFieldLabel: searchHint, textInputAction: textInputAction, searchFieldStyle: searchFieldStyle);
|
||||
|
||||
final String suggestions;
|
||||
final String result;
|
||||
|
|
Loading…
Reference in a new issue