mirror of
https://github.com/flutter/packages.git
synced 2025-07-04 09:38:17 +08:00
[flutter_markdown] Unable to use MarkdownElementBuilder to act those tags without children. (#3952)
fix https://github.com/flutter/flutter/issues/126402 - [ ] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes]. - [ ] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style]. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] All existing and new tests are passing.
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
## NEXT
|
||||
## 0.6.15
|
||||
|
||||
* Fixes unawaited_futures violations.
|
||||
* Updates minimum Flutter version to 3.3.
|
||||
* Aligns Dart and Flutter SDK constraints.
|
||||
* Replace `describeEnum` with the `name` getter.
|
||||
* Supports custom rendering of tags without children.
|
||||
|
||||
## 0.6.14
|
||||
|
||||
|
@ -454,7 +454,11 @@ class MarkdownBuilder implements md.NodeVisitor {
|
||||
final Widget? child =
|
||||
builders[tag]!.visitElementAfter(element, styleSheet.styles[tag]);
|
||||
if (child != null) {
|
||||
current.children[0] = child;
|
||||
if (current.children.isEmpty) {
|
||||
current.children.add(child);
|
||||
} else {
|
||||
current.children[0] = child;
|
||||
}
|
||||
}
|
||||
} else if (tag == 'img') {
|
||||
// create an image widget for this image
|
||||
|
@ -4,7 +4,7 @@ description: A Markdown renderer for Flutter. Create rich text output,
|
||||
formatted with simple Markdown tags.
|
||||
repository: https://github.com/flutter/packages/tree/main/packages/flutter_markdown
|
||||
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+flutter_markdown%22
|
||||
version: 0.6.14
|
||||
version: 0.6.15
|
||||
|
||||
environment:
|
||||
sdk: ">=2.18.0 <4.0.0"
|
||||
|
@ -112,6 +112,30 @@ void defineTests() {
|
||||
expect(widgetSpan.child, isInstanceOf<Container>());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'Custom rendering of tags without children',
|
||||
(WidgetTester tester) async {
|
||||
const String data = '';
|
||||
await tester.pumpWidget(
|
||||
boilerplate(
|
||||
Markdown(
|
||||
data: data,
|
||||
builders: <String, MarkdownElementBuilder>{
|
||||
'img': ImgBuilder(),
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final Finder imageFinder = find.byType(Image);
|
||||
expect(imageFinder, findsNothing);
|
||||
final Finder textFinder = find.byType(Text);
|
||||
expect(textFinder, findsOneWidget);
|
||||
final Text textWidget = tester.widget(find.byType(Text));
|
||||
expect(textWidget.data, 'foo');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class SubscriptSyntax extends md.InlineSyntax {
|
||||
@ -225,3 +249,10 @@ class ContainerBuilder2 extends MarkdownElementBuilder {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ImgBuilder extends MarkdownElementBuilder {
|
||||
@override
|
||||
Widget? visitElementAfter(md.Element element, TextStyle? preferredStyle) {
|
||||
return Text('foo', style: preferredStyle);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user