From 5d37de2685b8fcc151f61e121289c3dcbaee4623 Mon Sep 17 00:00:00 2001 From: MH Johnson Date: Wed, 15 Jan 2020 01:23:02 -0500 Subject: [PATCH] [Gallery] Fix text contrast ratio on homepage and contacts demo (#48752) --- .../lib/demo/contacts_demo.dart | 6 ++-- .../flutter_gallery/lib/gallery/options.dart | 7 ++-- .../test/accessibility_test.dart | 32 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/contacts_demo.dart b/examples/flutter_gallery/lib/demo/contacts_demo.dart index a30889e8b4..e3552e14c9 100644 --- a/examples/flutter_gallery/lib/demo/contacts_demo.dart +++ b/examples/flutter_gallery/lib/demo/contacts_demo.dart @@ -169,9 +169,9 @@ class ContactsDemoState extends State { const DecoratedBox( decoration: BoxDecoration( gradient: LinearGradient( - begin: Alignment(0.0, -1.0), - end: Alignment(0.0, -0.4), - colors: [Color(0x60000000), Color(0x00000000)], + begin: Alignment.topCenter, + end: Alignment(0, .35), + colors: [Color(0xC0000000), Color(0x00000000)], ), ), ), diff --git a/examples/flutter_gallery/lib/gallery/options.dart b/examples/flutter_gallery/lib/gallery/options.dart index c939fca6a4..c6dfac6645 100644 --- a/examples/flutter_gallery/lib/gallery/options.dart +++ b/examples/flutter_gallery/lib/gallery/options.dart @@ -194,9 +194,10 @@ class _Heading extends StatelessWidget { final ThemeData theme = Theme.of(context); return _OptionsItem( child: DefaultTextStyle( - style: theme.textTheme.body1.copyWith( + style: theme.textTheme.title.copyWith( fontFamily: 'GoogleSans', - color: theme.accentColor, + color: theme.colorScheme.onPrimary, + fontWeight: FontWeight.w700, ), child: Semantics( child: Text(text), @@ -525,7 +526,7 @@ class GalleryOptionsPage extends StatelessWidget { _TextDirectionItem(options, onOptionsChanged), _TimeDilationItem(options, onOptionsChanged), const Divider(), - const _Heading('Platform mechanics'), + const ExcludeSemantics(child: _Heading('Platform mechanics')), _PlatformItem(options, onOptionsChanged), ..._enabledDiagnosticItems(), const Divider(), diff --git a/examples/flutter_gallery/test/accessibility_test.dart b/examples/flutter_gallery/test/accessibility_test.dart index c0a7e018ae..83e8d4faff 100644 --- a/examples/flutter_gallery/test/accessibility_test.dart +++ b/examples/flutter_gallery/test/accessibility_test.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'package:flutter/material.dart'; +import 'package:flutter_gallery/gallery/app.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_gallery/demo/all.dart'; import 'package:flutter_gallery/gallery/themes.dart'; @@ -756,4 +757,35 @@ void main() { }); } }); + + group('Gallery home page meets text contrast guidelines', () { + testWidgets('options menu', (WidgetTester tester) async { + await tester.pumpWidget(const GalleryApp(testMode: true)); + await tester.tap(find.byTooltip('Toggle options page')); + await tester.pumpAndSettle(); + await expectLater(tester, meetsGuideline(textContrastGuideline)); + }); + + testWidgets('options menu - dark theme', (WidgetTester tester) async { + await tester.pumpWidget(const GalleryApp(testMode: true)); + await tester.tap(find.byTooltip('Toggle options page')); + await tester.pumpAndSettle(); + + // Toggle dark mode. + final Finder themeToggleContainer = find.ancestor( + of: find.text('Theme'), + matching: find.byType(Container), + ); + final Finder themeMenuButton = find.descendant( + of: themeToggleContainer, + matching: find.byIcon(Icons.arrow_drop_down), + ); + await tester.tap(themeMenuButton); + await tester.pumpAndSettle(); + await tester.tap(find.text('Dark')); + await tester.pumpAndSettle(); + + await expectLater(tester, meetsGuideline(textContrastGuideline)); + }); + }); }