Unverified Commit e3f8d055 authored by Anthony's avatar Anthony Committed by GitHub

Show search app bar theme (#37962)

Use the entire appBarTheme from the showSearch delegate for the search pages appBar theme, rather than just a select set of fields.
parent b63cb441
...@@ -198,6 +198,9 @@ abstract class SearchDelegate<T> { ...@@ -198,6 +198,9 @@ abstract class SearchDelegate<T> {
primaryIconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey), primaryIconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey),
primaryColorBrightness: Brightness.light, primaryColorBrightness: Brightness.light,
primaryTextTheme: theme.textTheme, primaryTextTheme: theme.textTheme,
inputDecorationTheme: theme.inputDecorationTheme.copyWith(
border: InputBorder.none,
),
); );
} }
...@@ -500,28 +503,24 @@ class _SearchPageState<T> extends State<_SearchPage<T>> { ...@@ -500,28 +503,24 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
namesRoute: true, namesRoute: true,
label: routeName, label: routeName,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: _ThemedPreferredSizeWidget(
backgroundColor: theme.primaryColor, theme: theme,
iconTheme: theme.primaryIconTheme, child: AppBar(
textTheme: theme.primaryTextTheme, leading: widget.delegate.buildLeading(context),
brightness: theme.primaryColorBrightness, title: TextField(
leading: widget.delegate.buildLeading(context), controller: widget.delegate._queryTextController,
title: TextField( focusNode: focusNode,
controller: widget.delegate._queryTextController, textInputAction: widget.delegate.textInputAction,
focusNode: focusNode, keyboardType: widget.delegate.keyboardType,
style: theme.textTheme.title, onSubmitted: (String _) {
textInputAction: widget.delegate.textInputAction, widget.delegate.showResults(context);
keyboardType: widget.delegate.keyboardType, },
onSubmitted: (String _) { decoration: InputDecoration(
widget.delegate.showResults(context); hintText: searchFieldLabel,
}, ),
decoration: InputDecoration(
border: InputBorder.none,
hintText: searchFieldLabel,
hintStyle: theme.inputDecorationTheme.hintStyle,
), ),
actions: widget.delegate.buildActions(context),
), ),
actions: widget.delegate.buildActions(context),
), ),
body: AnimatedSwitcher( body: AnimatedSwitcher(
duration: const Duration(milliseconds: 300), duration: const Duration(milliseconds: 300),
...@@ -531,3 +530,21 @@ class _SearchPageState<T> extends State<_SearchPage<T>> { ...@@ -531,3 +530,21 @@ class _SearchPageState<T> extends State<_SearchPage<T>> {
); );
} }
} }
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;
}
...@@ -100,9 +100,13 @@ void main() { ...@@ -100,9 +100,13 @@ void main() {
await tester.tap(find.byTooltip('Search')); await tester.tap(find.byTooltip('Search'));
await tester.pumpAndSettle(); await tester.pumpAndSettle();
final TextField textField = tester.widget<TextField>(find.byType(TextField)); expect(tester.widget<RichText>(
final Color hintColor = textField.decoration.hintStyle.color; find.descendant(
expect(hintColor, delegate.hintTextColor); of: find.byType(TextField),
matching: find.byType(RichText),
)).text.style.color,
Colors.green,
);
}); });
testWidgets('Requests suggestions', (WidgetTester tester) async { testWidgets('Requests suggestions', (WidgetTester tester) async {
...@@ -638,6 +642,49 @@ void main() { ...@@ -638,6 +642,49 @@ void main() {
semantics.dispose(); 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<Material>(
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<InputDecorator>(
find.descendant(
of: find.byType(AppBar),
matching: find.byType(InputDecorator),
)).decoration.enabledBorder,
InputBorder.none,
);
});
} }
class TestHomePage extends StatelessWidget { class TestHomePage extends StatelessWidget {
...@@ -748,3 +795,24 @@ class _TestSearchDelegate extends SearchDelegate<String> { ...@@ -748,3 +795,24 @@ class _TestSearchDelegate extends SearchDelegate<String> {
return actions; 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,
),
);
}
}
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