diff --git a/packages/flutter/lib/src/material/search.dart b/packages/flutter/lib/src/material/search.dart index 1fa2bfc22c..52cf874238 100644 --- a/packages/flutter/lib/src/material/search.dart +++ b/packages/flutter/lib/src/material/search.dart @@ -198,6 +198,9 @@ abstract class SearchDelegate { primaryIconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey), primaryColorBrightness: Brightness.light, primaryTextTheme: theme.textTheme, + inputDecorationTheme: theme.inputDecorationTheme.copyWith( + border: InputBorder.none, + ), ); } @@ -500,28 +503,24 @@ class _SearchPageState extends State<_SearchPage> { namesRoute: true, label: routeName, child: Scaffold( - appBar: AppBar( - backgroundColor: theme.primaryColor, - iconTheme: theme.primaryIconTheme, - textTheme: theme.primaryTextTheme, - brightness: theme.primaryColorBrightness, - leading: widget.delegate.buildLeading(context), - title: TextField( - controller: widget.delegate._queryTextController, - focusNode: focusNode, - style: theme.textTheme.title, - textInputAction: widget.delegate.textInputAction, - keyboardType: widget.delegate.keyboardType, - onSubmitted: (String _) { - widget.delegate.showResults(context); - }, - decoration: InputDecoration( - border: InputBorder.none, - hintText: searchFieldLabel, - hintStyle: theme.inputDecorationTheme.hintStyle, + appBar: _ThemedPreferredSizeWidget( + theme: theme, + child: AppBar( + leading: widget.delegate.buildLeading(context), + title: TextField( + controller: widget.delegate._queryTextController, + focusNode: focusNode, + textInputAction: widget.delegate.textInputAction, + keyboardType: widget.delegate.keyboardType, + onSubmitted: (String _) { + widget.delegate.showResults(context); + }, + decoration: InputDecoration( + hintText: searchFieldLabel, + ), ), + actions: widget.delegate.buildActions(context), ), - actions: widget.delegate.buildActions(context), ), body: AnimatedSwitcher( duration: const Duration(milliseconds: 300), @@ -531,3 +530,21 @@ class _SearchPageState extends State<_SearchPage> { ); } } + +class _ThemedPreferredSizeWidget extends StatelessWidget implements PreferredSizeWidget { + const _ThemedPreferredSizeWidget({ this.theme, this.child }); + + final ThemeData theme; + final PreferredSizeWidget child; + + @override + Widget build(BuildContext context) { + return Theme( + data: theme, + child: child, + ); + } + + @override + Size get preferredSize => child.preferredSize; +} diff --git a/packages/flutter/test/material/search_test.dart b/packages/flutter/test/material/search_test.dart index 297d1c1c5c..e4ce9f29cf 100644 --- a/packages/flutter/test/material/search_test.dart +++ b/packages/flutter/test/material/search_test.dart @@ -100,9 +100,13 @@ void main() { await tester.tap(find.byTooltip('Search')); await tester.pumpAndSettle(); - final TextField textField = tester.widget(find.byType(TextField)); - final Color hintColor = textField.decoration.hintStyle.color; - expect(hintColor, delegate.hintTextColor); + expect(tester.widget( + find.descendant( + of: find.byType(TextField), + matching: find.byType(RichText), + )).text.style.color, + Colors.green, + ); }); testWidgets('Requests suggestions', (WidgetTester tester) async { @@ -638,6 +642,49 @@ void main() { semantics.dispose(); }); }); + + testWidgets('delegate appBarTheme is applied to the AppBar color on the search page', (WidgetTester tester) async { + final _AppBarThemeTestDelegate delegate = _AppBarThemeTestDelegate( + appBarColor: Colors.green, + ); + await tester.pumpWidget(TestHomePage( + delegate: delegate, + )); + + // Open the search page. + await tester.tap(find.byTooltip('Search')); + await tester.pumpAndSettle(); + + expect(tester.widget( + find.descendant( + of: find.byType(AppBar), + matching: find.byType(Material), + )).color, + Colors.green, + ); + }); + + testWidgets('delegate appBarTheme is applied to the enabledBorder of the TextField on the search page', (WidgetTester tester) async { + final _AppBarThemeTestDelegate delegate = _AppBarThemeTestDelegate( + enabledBorder: InputBorder.none, + ); + await tester.pumpWidget(TestHomePage( + delegate: delegate, + )); + + // Open the search page. + await tester.tap(find.byTooltip('Search')); + await tester.pumpAndSettle(); + await tester.enterText(find.byType(TextField), 'abc'); + + expect(tester.widget( + find.descendant( + of: find.byType(AppBar), + matching: find.byType(InputDecorator), + )).decoration.enabledBorder, + InputBorder.none, + ); + }); } class TestHomePage extends StatelessWidget { @@ -748,3 +795,24 @@ class _TestSearchDelegate extends SearchDelegate { return actions; } } + +class _AppBarThemeTestDelegate extends _TestSearchDelegate { + _AppBarThemeTestDelegate({this.appBarColor, this.enabledBorder}); + + final Color appBarColor; + final InputBorder enabledBorder; + + @override + ThemeData appBarTheme(BuildContext context) { + final ThemeData theme = Theme.of(context); + return theme.copyWith( + primaryColor: appBarColor, + appBarTheme: theme.appBarTheme.copyWith( + color: appBarColor, + ), + inputDecorationTheme: theme.inputDecorationTheme.copyWith( + enabledBorder: enabledBorder, + ), + ); + } +}