diff --git a/packages/flutter_markdown/lib/src/builder.dart b/packages/flutter_markdown/lib/src/builder.dart index 617240b578..a8856e7e99 100644 --- a/packages/flutter_markdown/lib/src/builder.dart +++ b/packages/flutter_markdown/lib/src/builder.dart @@ -296,7 +296,7 @@ class MarkdownBuilder implements md.NodeVisitor { child = _buildRichText( TextSpan( style: _isInBlockquote - ? _inlines.last.style!.merge(styleSheet.blockquote) + ? styleSheet.blockquote!.merge(_inlines.last.style) : _inlines.last.style, text: _isInBlockquote ? text.text : trimText(text.text), recognizer: _linkHandlers.isNotEmpty ? _linkHandlers.last : null, diff --git a/packages/flutter_markdown/test/blockquote_test.dart b/packages/flutter_markdown/test/blockquote_test.dart index 6053d5b1c0..83e48b41fe 100644 --- a/packages/flutter_markdown/test/blockquote_test.dart +++ b/packages/flutter_markdown/test/blockquote_test.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -24,5 +25,82 @@ void defineTests() { expectTextStrings(widgets, ['quote']); }, ); + + testWidgets( + 'should work with styling', + (WidgetTester tester) async { + final ThemeData theme = ThemeData.light().copyWith( + textTheme: textTheme, + ); + final MarkdownStyleSheet styleSheet = MarkdownStyleSheet.fromTheme( + theme, + ); + + const String data = + '> this is a link: [Markdown guide](https://www.markdownguide.org) and this is **bold** and *italic*'; + await tester.pumpWidget( + boilerplate( + MarkdownBody( + data: data, + styleSheet: styleSheet, + ), + ), + ); + + final Iterable widgets = tester.allWidgets; + final DecoratedBox blockQuoteContainer = tester.widget( + find.byType(DecoratedBox), + ); + final RichText qouteText = tester.widget(find.byType(RichText)); + final List styledTextParts = + (qouteText.text as TextSpan).children!.cast(); + + expectTextStrings( + widgets, + ['this is a link: Markdown guide and this is bold and italic'], + ); + expect( + (blockQuoteContainer.decoration as BoxDecoration).color, + (styleSheet.blockquoteDecoration as BoxDecoration).color, + ); + expect( + (blockQuoteContainer.decoration as BoxDecoration).borderRadius, + (styleSheet.blockquoteDecoration as BoxDecoration).borderRadius, + ); + + /// this is a link + expect(styledTextParts[0].text, 'this is a link: '); + expect( + styledTextParts[0].style!.color, + theme.textTheme.bodyText2!.color, + ); + + /// Markdown guide + expect(styledTextParts[1].text, 'Markdown guide'); + expect(styledTextParts[1].style!.color, Colors.blue); + + /// and this is + expect(styledTextParts[2].text, ' and this is '); + expect( + styledTextParts[2].style!.color, + theme.textTheme.bodyText2!.color, + ); + + /// bold + expect(styledTextParts[3].text, 'bold'); + expect(styledTextParts[3].style!.fontWeight, FontWeight.bold); + + /// and + expect(styledTextParts[4].text, ' and '); + expect( + styledTextParts[4].style!.color, + theme.textTheme.bodyText2!.color, + ); + + /// italic + expect(styledTextParts[5].text, 'italic'); + expect(styledTextParts[5].style!.fontStyle, FontStyle.italic); + }, + ); }); }