-
Notifications
You must be signed in to change notification settings - Fork 401
Fix unreadable release notes blockquote in dark theme #9957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
srawlins
merged 2 commits into
flutter:master
from
Yusufihsangorgel:issue-9945-blockquote-contrast-v5
Aug 12, 2026
+116
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/devtools_app/test/shared/ui/side_panel_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| // Copyright 2026 The Flutter Authors | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd. | ||
|
|
||
| import 'package:devtools_app/devtools_app.dart'; | ||
| import 'package:devtools_app_shared/ui.dart'; | ||
| import 'package:devtools_app_shared/utils.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| /// The smallest contrast ratio WCAG 2.1 accepts for body text at level AA. | ||
| /// | ||
| /// See https://www.w3.org/TR/WCAG21/#contrast-minimum. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice docs |
||
| const _minimumContrastRatio = 4.5; | ||
|
|
||
| void main() { | ||
| setUp(() { | ||
| setGlobal(IdeTheme, IdeTheme()); | ||
| }); | ||
|
|
||
| group('$SidePanelViewer', () { | ||
| // `MarkdownStyleSheet.fromTheme` fills blockquotes with | ||
| // `Colors.blue.shade100` but takes the text color from the theme, so a | ||
| // release note that opens with a blockquote drew `onSurface` text on light | ||
| // blue in the dark theme. | ||
| // Regression test for https://github.com/flutter/devtools/issues/9945. | ||
| for (final useDarkTheme in [true, false]) { | ||
| final themeName = useDarkTheme ? 'dark' : 'light'; | ||
| testWidgets('blockquote text is legible in the $themeName theme', ( | ||
| tester, | ||
| ) async { | ||
| const summary = 'Release notes for Dart and Flutter DevTools.'; | ||
| final controller = SidePanelController(); | ||
| await tester.pumpWidget( | ||
| MaterialApp( | ||
| theme: themeFor( | ||
| isDarkTheme: useDarkTheme, | ||
| ideTheme: IdeTheme(), | ||
| theme: ThemeData( | ||
| useMaterial3: true, | ||
| colorScheme: useDarkTheme ? darkColorScheme : lightColorScheme, | ||
| ), | ||
| ), | ||
| home: SidePanelViewer(controller: controller), | ||
| ), | ||
| ); | ||
| controller.markdown.value = '# Release notes\n\n> $summary'; | ||
| controller.toggleVisibility(true); | ||
| await tester.pumpAndSettle(); | ||
|
|
||
| final summaryFinder = find.byWidgetPredicate( | ||
| (widget) => | ||
| widget is RichText && widget.text.toPlainText() == summary, | ||
| ); | ||
| expect(summaryFinder, findsOneWidget); | ||
|
|
||
| final textColor = _colorOfSpan( | ||
| tester.widget<RichText>(summaryFinder).text, | ||
| summary, | ||
| ); | ||
| final fillColor = tester | ||
| .widgetList<DecoratedBox>( | ||
| find.ancestor( | ||
| of: summaryFinder, | ||
| matching: find.byType(DecoratedBox), | ||
| ), | ||
| ) | ||
| .map((box) => box.decoration) | ||
| .whereType<BoxDecoration>() | ||
| .map((decoration) => decoration.color) | ||
| .nonNulls | ||
| .first; | ||
|
|
||
| expect( | ||
| _contrastRatio(textColor!, fillColor), | ||
| greaterThanOrEqualTo(_minimumContrastRatio), | ||
| ); | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /// The color the span holding [text] is painted with, or null if [root] holds | ||
| /// no such span. | ||
| Color? _colorOfSpan(InlineSpan root, String text) { | ||
| Color? color; | ||
| root.visitChildren((span) { | ||
| if (span is TextSpan && span.text == text) { | ||
| color = span.style?.color; | ||
| return false; | ||
| } | ||
| return true; | ||
| }); | ||
| return color; | ||
| } | ||
|
|
||
| /// The WCAG contrast ratio between [a] and [b], from 1 (identical) to 21 | ||
| /// (black on white). | ||
| double _contrastRatio(Color a, Color b) { | ||
| final luminances = [a.computeLuminance(), b.computeLuminance()]..sort(); | ||
| return (luminances.last + 0.05) / (luminances.first + 0.05); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MUST-FIX] Instantiating
MarkdownStyleSheetdirectly via its default constructor will result in a stylesheet where all other text styles (such asp,h1,code, etc.) arenull. This causes theMarkdownwidget to fall back to default unstyled text, losing all theme-derived styles (fonts, sizes, colors) for the rest of the release notes.To preserve the theme's styles while overriding only the blockquote decoration, use
MarkdownStyleSheet.fromTheme(theme).copyWith(...)instead.References
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The widget merges this sheet over the theme one. flutter_markdown resolves
kFallbackStyle(context, widget.styleSheetTheme).merge(widget.styleSheet)before parsing,widget.dart:391in 0.7.7, and merge keeps every field the override leaves null. I probed this exact sheet on a dark theme,merged.pstays equal toMarkdownStyleSheet.fromTheme(theme).pwhile the blockquote fill changes. I'm keeping the minimal override.