Unverified Commit f37a91a7 authored by Leonardo Emili's avatar Leonardo Emili Committed by GitHub

Add searchFieldStyle (#54674)

parent cf0fcd45
...@@ -119,6 +119,7 @@ abstract class SearchDelegate<T> { ...@@ -119,6 +119,7 @@ abstract class SearchDelegate<T> {
/// {@end-tool} /// {@end-tool}
SearchDelegate({ SearchDelegate({
this.searchFieldLabel, this.searchFieldLabel,
this.searchFieldStyle,
this.keyboardType, this.keyboardType,
this.textInputAction = TextInputAction.search, this.textInputAction = TextInputAction.search,
}); });
...@@ -264,6 +265,11 @@ abstract class SearchDelegate<T> { ...@@ -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. /// If this value is set to null, the value of MaterialLocalizations.of(context).searchFieldLabel will be used instead.
final String searchFieldLabel; 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. /// The type of action button to use for the keyboard.
/// ///
/// Defaults to the default value specified in [TextField]. /// Defaults to the default value specified in [TextField].
...@@ -315,7 +321,6 @@ enum _SearchBody { ...@@ -315,7 +321,6 @@ enum _SearchBody {
results, results,
} }
class _SearchPageRoute<T> extends PageRoute<T> { class _SearchPageRoute<T> extends PageRoute<T> {
_SearchPageRoute({ _SearchPageRoute({
@required this.delegate, @required this.delegate,
...@@ -469,6 +474,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> { ...@@ -469,6 +474,8 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
final ThemeData theme = widget.delegate.appBarTheme(context); final ThemeData theme = widget.delegate.appBarTheme(context);
final String searchFieldLabel = widget.delegate.searchFieldLabel final String searchFieldLabel = widget.delegate.searchFieldLabel
?? MaterialLocalizations.of(context).searchFieldLabel; ?? MaterialLocalizations.of(context).searchFieldLabel;
final TextStyle searchFieldStyle = widget.delegate.searchFieldStyle
?? theme.inputDecorationTheme.hintStyle;
Widget body; Widget body;
switch(widget.delegate._currentBody) { switch(widget.delegate._currentBody) {
case _SearchBody.suggestions: case _SearchBody.suggestions:
...@@ -521,7 +528,7 @@ class _SearchPageState<T> extends State<_SearchPage<T>> { ...@@ -521,7 +528,7 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
decoration: InputDecoration( decoration: InputDecoration(
border: InputBorder.none, border: InputBorder.none,
hintText: searchFieldLabel, hintText: searchFieldLabel,
hintStyle: theme.inputDecorationTheme.hintStyle, hintStyle: searchFieldStyle,
), ),
), ),
actions: widget.delegate.buildActions(context), actions: widget.delegate.buildActions(context),
......
...@@ -509,6 +509,23 @@ void main() { ...@@ -509,6 +509,23 @@ void main() {
expect(find.text(searchHint), findsOneWidget); 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 { testWidgets('keyboard show search button by default', (WidgetTester tester) async {
final _TestSearchDelegate delegate = _TestSearchDelegate(); final _TestSearchDelegate delegate = _TestSearchDelegate();
...@@ -697,9 +714,10 @@ class _TestSearchDelegate extends SearchDelegate<String> { ...@@ -697,9 +714,10 @@ class _TestSearchDelegate extends SearchDelegate<String> {
this.suggestions = 'Suggestions', this.suggestions = 'Suggestions',
this.result = 'Result', this.result = 'Result',
this.actions = const <Widget>[], this.actions = const <Widget>[],
TextStyle searchFieldStyle,
String searchHint, String searchHint,
TextInputAction textInputAction = TextInputAction.search, TextInputAction textInputAction = TextInputAction.search,
}) : super(searchFieldLabel: searchHint, textInputAction: textInputAction); }) : super(searchFieldLabel: searchHint, textInputAction: textInputAction, searchFieldStyle: searchFieldStyle);
final String suggestions; final String suggestions;
final String result; final String result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment