Skip to content

Commit 1bc8402

Browse files
guojiexjustinmc
authored andcommitted
Add hintStyle in SearchDelegate (flutter#30388)
SearchDelegate hintStyle parameter
1 parent 336e4c4 commit 1bc8402

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/flutter/lib/src/material/search.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
466466
decoration: InputDecoration(
467467
border: InputBorder.none,
468468
hintText: searchFieldLabel,
469+
hintStyle: theme.inputDecorationTheme.hintStyle,
469470
),
470471
),
471472
actions: widget.delegate.buildActions(context),

packages/flutter/test/material/search_test.dart

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,20 @@ void main() {
9191
expect(find.text('Suggestions'), findsOneWidget);
9292
});
9393

94+
testWidgets('Hint text color overridden', (WidgetTester tester) async {
95+
final _TestSearchDelegate delegate = _TestSearchDelegate();
96+
97+
await tester.pumpWidget(TestHomePage(
98+
delegate: delegate,
99+
));
100+
await tester.tap(find.byTooltip('Search'));
101+
await tester.pumpAndSettle();
102+
103+
final TextField textField = tester.widget<TextField>(find.byType(TextField));
104+
final Color hintColor = textField.decoration.hintStyle.color;
105+
expect(hintColor, delegate.hintTextColor);
106+
});
107+
94108
testWidgets('Requests suggestions', (WidgetTester tester) async {
95109
final _TestSearchDelegate delegate = _TestSearchDelegate();
96110

@@ -644,6 +658,15 @@ class _TestSearchDelegate extends SearchDelegate<String> {
644658
final String suggestions;
645659
final String result;
646660
final List<Widget> actions;
661+
final Color hintTextColor = Colors.green;
662+
663+
@override
664+
ThemeData appBarTheme(BuildContext context) {
665+
final ThemeData theme = Theme.of(context);
666+
return theme.copyWith(
667+
inputDecorationTheme: InputDecorationTheme(hintStyle: TextStyle(color: hintTextColor)),
668+
);
669+
}
647670

648671
@override
649672
Widget buildLeading(BuildContext context) {
@@ -680,4 +703,4 @@ class _TestSearchDelegate extends SearchDelegate<String> {
680703
List<Widget> buildActions(BuildContext context) {
681704
return actions;
682705
}
683-
}
706+
}

0 commit comments

Comments
 (0)