Show tooltip for links

This commit is contained in:
Sarah Jamie Lewis 2022-01-18 15:03:54 -08:00
parent 1700306c78
commit ca44fd798c
1 changed files with 32 additions and 13 deletions

View File

@ -353,20 +353,24 @@ TextSpan buildTextSpan(
(element) { (element) {
if (element is LinkableElement) { if (element is LinkableElement) {
if (useMouseRegion) { if (useMouseRegion) {
return LinkableSpan( return TooltipSpan(
mouseCursor: SystemMouseCursors.click, message: element.url,
inlineSpan: TextSpan( inlineSpan: LinkableSpan(
text: element.text, mouseCursor: SystemMouseCursors.click,
style: linkStyle, inlineSpan: TextSpan(
recognizer: onOpen != null ? (TapGestureRecognizer()..onTap = () => onOpen(element)) : null, text: element.text,
), style: linkStyle,
); recognizer: onOpen != null ? (TapGestureRecognizer()..onTap = () => onOpen(element)) : null,
),
));
} else { } else {
return TextSpan( return TooltipSpan(
text: element.text, message: element.url,
style: linkStyle, inlineSpan: TextSpan(
recognizer: onOpen != null ? (TapGestureRecognizer()..onTap = () => onOpen(element)) : null, text: element.text,
); style: linkStyle,
recognizer: onOpen != null ? (TapGestureRecognizer()..onTap = () => onOpen(element)) : null,
));
} }
} else { } else {
return TextSpan( return TextSpan(
@ -378,3 +382,18 @@ TextSpan buildTextSpan(
).toList(), ).toList(),
); );
} }
// Show a tooltip over an inlined element in a Rich Text widget.
class TooltipSpan extends WidgetSpan {
TooltipSpan({
required String message,
required InlineSpan inlineSpan,
}) : super(
child: Tooltip(
message: message,
child: Text.rich(
inlineSpan,
),
),
);
}