Proper light/dark colors, and test that text is not color of background (#67679)
This commit is contained in:
parent
bacc03daf9
commit
c2bb928981
@ -199,7 +199,9 @@ abstract class SearchDelegate<T> {
|
|||||||
final ThemeData theme = Theme.of(context)!;
|
final ThemeData theme = Theme.of(context)!;
|
||||||
assert(theme != null);
|
assert(theme != null);
|
||||||
return theme.copyWith(
|
return theme.copyWith(
|
||||||
primaryColor: Colors.white,
|
primaryColor: theme.brightness == Brightness.dark
|
||||||
|
? theme.primaryColor
|
||||||
|
: Colors.white,
|
||||||
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,
|
||||||
|
@ -691,6 +691,56 @@ void main() {
|
|||||||
semantics.dispose();
|
semantics.dispose();
|
||||||
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.iOS, TargetPlatform.macOS }));
|
}, 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 {
|
class TestHomePage extends StatelessWidget {
|
||||||
@ -700,16 +750,19 @@ class TestHomePage extends StatelessWidget {
|
|||||||
required this.delegate,
|
required this.delegate,
|
||||||
this.passInInitialQuery = false,
|
this.passInInitialQuery = false,
|
||||||
this.initialQuery,
|
this.initialQuery,
|
||||||
|
this.themeData,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final List<String?>? results;
|
final List<String?>? results;
|
||||||
final SearchDelegate<String> delegate;
|
final SearchDelegate<String> delegate;
|
||||||
final bool passInInitialQuery;
|
final bool passInInitialQuery;
|
||||||
|
final ThemeData? themeData;
|
||||||
final String? initialQuery;
|
final String? initialQuery;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
theme: themeData,
|
||||||
home: Builder(builder: (BuildContext context) {
|
home: Builder(builder: (BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@ -749,11 +802,13 @@ 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>[],
|
||||||
|
this.defaultAppBarTheme = false,
|
||||||
TextStyle? searchFieldStyle,
|
TextStyle? searchFieldStyle,
|
||||||
String? searchHint,
|
String? searchHint,
|
||||||
TextInputAction textInputAction = TextInputAction.search,
|
TextInputAction textInputAction = TextInputAction.search,
|
||||||
}) : super(searchFieldLabel: searchHint, textInputAction: textInputAction, searchFieldStyle: searchFieldStyle);
|
}) : super(searchFieldLabel: searchHint, textInputAction: textInputAction, searchFieldStyle: searchFieldStyle);
|
||||||
|
|
||||||
|
final bool defaultAppBarTheme;
|
||||||
final String suggestions;
|
final String suggestions;
|
||||||
final String result;
|
final String result;
|
||||||
final List<Widget> actions;
|
final List<Widget> actions;
|
||||||
@ -761,6 +816,9 @@ class _TestSearchDelegate extends SearchDelegate<String> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
ThemeData appBarTheme(BuildContext context) {
|
ThemeData appBarTheme(BuildContext context) {
|
||||||
|
if (defaultAppBarTheme) {
|
||||||
|
return super.appBarTheme(context);
|
||||||
|
}
|
||||||
final ThemeData theme = Theme.of(context)!;
|
final ThemeData theme = Theme.of(context)!;
|
||||||
return theme.copyWith(
|
return theme.copyWith(
|
||||||
inputDecorationTheme: InputDecorationTheme(hintStyle: TextStyle(color: hintTextColor)),
|
inputDecorationTheme: InputDecorationTheme(hintStyle: TextStyle(color: hintTextColor)),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user