diff --git a/packages/flutter/lib/src/material/search.dart b/packages/flutter/lib/src/material/search.dart index 1660e89f90..bc051577a9 100644 --- a/packages/flutter/lib/src/material/search.dart +++ b/packages/flutter/lib/src/material/search.dart @@ -119,6 +119,7 @@ abstract class SearchDelegate { /// {@end-tool} SearchDelegate({ this.searchFieldLabel, + this.searchFieldStyle, this.keyboardType, this.textInputAction = TextInputAction.search, }); @@ -264,6 +265,11 @@ abstract class SearchDelegate { /// 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 extends PageRoute { _SearchPageRoute({ @required this.delegate, @@ -469,6 +474,8 @@ class _SearchPageState extends State<_SearchPage> { 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 extends State<_SearchPage> { decoration: InputDecoration( border: InputBorder.none, hintText: searchFieldLabel, - hintStyle: theme.inputDecorationTheme.hintStyle, + hintStyle: searchFieldStyle, ), ), actions: widget.delegate.buildActions(context), diff --git a/packages/flutter/test/material/search_test.dart b/packages/flutter/test/material/search_test.dart index 239db29c2b..d1c6e2dcce 100644 --- a/packages/flutter/test/material/search_test.dart +++ b/packages/flutter/test/material/search_test.dart @@ -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(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 { this.suggestions = 'Suggestions', this.result = 'Result', this.actions = const [], + 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;