Skip to content

Commit

Permalink
fix: added linkify to message token text widget (#1702)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggurdin authored Feb 4, 2025
1 parent 7c8f917 commit 72dcdb4
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/pangea/toolbar/widgets/message_token_text.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ 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';
import 'package:fluffychat/pangea/events/event_wrappers/pangea_message_event.dart';
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?
Expand Down Expand Up @@ -220,7 +222,8 @@ class MessageTextWidget extends StatelessWidget {
),
);
}
return TextSpan(
return LinkifySpan(
mouseCursor: SystemMouseCursors.click,
recognizer: TapGestureRecognizer()
..onTap =
onClick != null ? () => onClick?.call(tokenPosition) : null,
Expand All @@ -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) &&
Expand All @@ -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(),
Expand Down

0 comments on commit 72dcdb4

Please sign in to comment.