Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/widget/blocks/leaf/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ class LinkNode extends ElementNode {

LinkNode(this.attributes, this.linkConfig);

String get _url => attributes['href'] ?? '';

@override
InlineSpan build() {
final url = attributes['href'] ?? '';
return TextSpan(children: [
for (final child in children)
_toLinkInlineSpan(
child.build(),
() => _onLinkTap(linkConfig, url),
() => _onLinkTap(linkConfig, _url),
),
if (children.isNotEmpty)
// FIXME: this is a workaround, maybe need fixed by flutter framework.
Expand All @@ -42,18 +43,22 @@ class LinkNode extends ElementNode {
}

@override
TextStyle get style =>
parentStyle?.merge(linkConfig.style) ?? linkConfig.style;
TextStyle get style {
final style = linkConfig.styleBuilder?.call(_url) ?? linkConfig.style;
return parentStyle?.merge(style) ?? style;
}
}

///config class for link, tag: a
class LinkConfig implements LeafConfig {
final TextStyle Function(String url)? styleBuilder;
final TextStyle style;
final ValueCallback<String>? onTap;

const LinkConfig(
{this.style = const TextStyle(
color: Color(0xff0969da), decoration: TextDecoration.underline),
this.styleBuilder,
this.onTap});

@nonVirtual
Expand Down