Unverified Commit c2bb9289 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Proper light/dark colors, and test that text is not color of background (#67679)

parent bacc03da
......@@ -199,7 +199,9 @@ abstract class SearchDelegate<T> {
final ThemeData theme = Theme.of(context)!;
assert(theme != null);
return theme.copyWith(
primaryColor: Colors.white,
primaryColor: theme.brightness == Brightness.dark
? theme.primaryColor
: Colors.white,
primaryIconTheme: theme.primaryIconTheme.copyWith(color: Colors.grey),
primaryColorBrightness: Brightness.light,
primaryTextTheme: theme.textTheme,
......
......@@ -691,6 +691,56 @@ void main() {
semantics.dispose();
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
});
// Regression test for: https://github.com/flutter/flutter/issues/66781
testWidgets('text in search bar contrasts background (light mode)', (WidgetTester tester) async {
final ThemeData themeData = ThemeData.light();
final _TestSearchDelegate delegate = _TestSearchDelegate(
defaultAppBarTheme: true,
);
const String query = 'search query';
await tester.pumpWidget(TestHomePage(
delegate: delegate,
passInInitialQuery: true,
initialQuery: query,
themeData: themeData,
));
await tester.tap(find.byTooltip('Search'));
await tester.pumpAndSettle();
final AppBar appBar = tester.widget<AppBar>(find.byType(AppBar));
expect(appBar.backgroundColor, Colors.white);
final TextField textField = tester.widget<TextField>(find.byType(TextField));
expect(textField.style!.color, themeData.textTheme.bodyText1!.color);
expect(textField.style!.color, isNot(equals(Colors.white)));
});
// Regression test for: https://github.com/flutter/flutter/issues/66781
testWidgets('text in search bar contrasts background (dark mode)', (WidgetTester tester) async {
final ThemeData themeData = ThemeData.dark();
final _TestSearchDelegate delegate = _TestSearchDelegate(
defaultAppBarTheme: true,
);
const String query = 'search query';
await tester.pumpWidget(TestHomePage(
delegate: delegate,
passInInitialQuery: true,
initialQuery: query,
themeData: themeData,
));
await tester.tap(find.byTooltip('Search'));
await tester.pumpAndSettle();
final AppBar appBar = tester.widget<AppBar>(find.byType(AppBar));
expect(appBar.backgroundColor, themeData.primaryColor);
final TextField textField = tester.widget<TextField>(find.byType(TextField));
expect(textField.style!.color, themeData.textTheme.bodyText1!.color);
expect(textField.style!.color, isNot(equals(themeData.primaryColor)));
});
}
class TestHomePage extends StatelessWidget {
......@@ -700,16 +750,19 @@ class TestHomePage extends StatelessWidget {
required this.delegate,
this.passInInitialQuery = false,
this.initialQuery,
this.themeData,
}) : super(key: key);
final List<String?>? results;
final SearchDelegate<String> delegate;
final bool passInInitialQuery;
final ThemeData? themeData;
final String? initialQuery;
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: themeData,
home: Builder(builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(
......@@ -749,11 +802,13 @@ class _TestSearchDelegate extends SearchDelegate<String> {
this.suggestions = 'Suggestions',
this.result = 'Result',
this.actions = const <Widget>[],
this.defaultAppBarTheme = false,
TextStyle? searchFieldStyle,
String? searchHint,
TextInputAction textInputAction = TextInputAction.search,
}) : super(searchFieldLabel: searchHint, textInputAction: textInputAction, searchFieldStyle: searchFieldStyle);
final bool defaultAppBarTheme;
final String suggestions;
final String result;
final List<Widget> actions;
......@@ -761,6 +816,9 @@ class _TestSearchDelegate extends SearchDelegate<String> {
@override
ThemeData appBarTheme(BuildContext context) {
if (defaultAppBarTheme) {
return super.appBarTheme(context);
}
final ThemeData theme = Theme.of(context)!;
return theme.copyWith(
inputDecorationTheme: InputDecorationTheme(hintStyle: TextStyle(color: hintTextColor)),
......
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