From 72dcdb4fd531e4a7e65d01efa63d9ee8e226d4ea Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Tue, 4 Feb 2025 16:19:17 -0500 Subject: [PATCH] fix: added linkify to message token text widget (#1702) --- .../toolbar/widgets/message_token_text.dart | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pangea/toolbar/widgets/message_token_text.dart b/lib/pangea/toolbar/widgets/message_token_text.dart index fcb56cf10..0f7dc6aa1 100644 --- a/lib/pangea/toolbar/widgets/message_token_text.dart +++ b/lib/pangea/toolbar/widgets/message_token_text.dart @@ -2,6 +2,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:collection/collection.dart'; +import 'package:flutter_linkify/flutter_linkify.dart'; import 'package:fluffychat/config/app_config.dart'; import 'package:fluffychat/pangea/analytics_misc/message_analytics_controller.dart'; @@ -9,6 +10,7 @@ import 'package:fluffychat/pangea/events/event_wrappers/pangea_message_event.dar import 'package:fluffychat/pangea/events/models/pangea_token_model.dart'; import 'package:fluffychat/pangea/events/utils/message_text_util.dart'; import 'package:fluffychat/pangea/toolbar/enums/activity_type_enum.dart'; +import 'package:fluffychat/utils/url_launcher.dart'; import 'package:fluffychat/widgets/matrix.dart'; /// Question - does this need to be stateful or does this work? @@ -220,7 +222,8 @@ class MessageTextWidget extends StatelessWidget { ), ); } - return TextSpan( + return LinkifySpan( + mouseCursor: SystemMouseCursors.click, recognizer: TapGestureRecognizer() ..onTap = onClick != null ? () => onClick?.call(tokenPosition) : null, @@ -230,6 +233,10 @@ class MessageTextWidget extends StatelessWidget { backgroundColor: backgroundColor, ), ), + linkStyle: const TextStyle( + decoration: TextDecoration.underline, + ), + onOpen: (url) => UrlLauncher(context, url.url).launchUrl(), ); } else { if ((i > 0 || i < tokenPositions.length - 1) && @@ -244,9 +251,14 @@ class MessageTextWidget extends StatelessWidget { ), ); } - return TextSpan( + return LinkifySpan( text: substring, style: style, + options: const LinkifyOptions(humanize: false), + linkStyle: const TextStyle( + decoration: TextDecoration.underline, + ), + onOpen: (url) => UrlLauncher(context, url.url).launchUrl(), ); } }).toList(),