@@ -55,6 +55,9 @@ class FlyerChatTextMessage extends StatelessWidget {
5555 /// The color of the links in the received messages.
5656 final Color ? receivedLinksColor;
5757
58+ /// The color of the links in the received messages.
59+ final TextDecoration linksDecoration;
60+
5861 /// Text style for the message timestamp and status.
5962 final TextStyle ? timeStyle;
6063
@@ -96,6 +99,7 @@ class FlyerChatTextMessage extends StatelessWidget {
9699 this .receivedTextStyle,
97100 this .sentLinksColor,
98101 this .receivedLinksColor,
102+ this .linksDecoration = TextDecoration .underline,
99103 this .timeStyle,
100104 this .showTime = true ,
101105 this .showStatus = true ,
@@ -138,27 +142,30 @@ class FlyerChatTextMessage extends StatelessWidget {
138142 : null ;
139143
140144 final textContent = GptMarkdownTheme (
141- gptThemeData: GptMarkdownTheme .of (context).copyWith (
142- linkColor: isSentByMe ? sentLinksColor : receivedLinksColor,
143- linkHoverColor: isSentByMe ? sentLinksColor : receivedLinksColor,
144- ),
145+ gptThemeData: GptMarkdownTheme .of (context),
145146 child: GptMarkdown (
146147 message.text,
147- style:
148- _isOnlyEmoji
149- ? paragraphStyle? .copyWith (fontSize: onlyEmojiFontSize)
150- : paragraphStyle,
148+ followLinkColor: true ,
149+ style: _isOnlyEmoji ? paragraphStyle? .copyWith (fontSize: onlyEmojiFontSize) : paragraphStyle,
151150 onLinkTap: onLinkTap,
151+ linkBuilder: (context, span, href, onTap) {
152+ return GestureDetector (
153+ onTap: () => onLinkTap? .call (href, span.toStringShort ()),
154+ child: Text .rich (
155+ span,
156+ style: paragraphStyle? .copyWith (
157+ decorationColor: isSentByMe ? sentLinksColor : receivedLinksColor,
158+ decoration: linksDecoration,
159+ ),
160+ ),
161+ );
162+ },
152163 ),
153164 );
154165
155166 final linkPreviewWidget =
156167 linkPreviewPosition != LinkPreviewPosition .none
157- ? context.read <Builders >().linkPreviewBuilder? .call (
158- context,
159- message,
160- isSentByMe,
161- )
168+ ? context.read <Builders >().linkPreviewBuilder? .call (context, message, isSentByMe)
162169 : null ;
163170
164171 return ClipRRect (
@@ -173,10 +180,7 @@ class FlyerChatTextMessage extends StatelessWidget {
173180 Container (
174181 padding:
175182 _isOnlyEmoji
176- ? EdgeInsets .symmetric (
177- horizontal: (padding? .horizontal ?? 0 ) / 2 ,
178- vertical: 0 ,
179- )
183+ ? EdgeInsets .symmetric (horizontal: (padding? .horizontal ?? 0 ) / 2 , vertical: 0 )
180184 : padding,
181185 child: _buildContentBasedOnPosition (
182186 context: context,
@@ -200,10 +204,7 @@ class FlyerChatTextMessage extends StatelessWidget {
200204 Widget ? linkPreviewWidget,
201205 }) {
202206 final textDirection = Directionality .of (context);
203- final effectiveLinkPreviewPosition =
204- linkPreviewWidget != null
205- ? linkPreviewPosition
206- : LinkPreviewPosition .none;
207+ final effectiveLinkPreviewPosition = linkPreviewWidget != null ? linkPreviewPosition : LinkPreviewPosition .none;
207208
208209 return Stack (
209210 children: [
@@ -212,38 +213,30 @@ class FlyerChatTextMessage extends StatelessWidget {
212213 crossAxisAlignment: CrossAxisAlignment .start,
213214 children: [
214215 if (topWidget != null ) topWidget! ,
215- if (effectiveLinkPreviewPosition == LinkPreviewPosition .top)
216- linkPreviewWidget! ,
216+ if (effectiveLinkPreviewPosition == LinkPreviewPosition .top) linkPreviewWidget! ,
217217 timeAndStatusPosition == TimeAndStatusPosition .inline
218218 ? Row (
219219 mainAxisSize: MainAxisSize .min,
220220 crossAxisAlignment: CrossAxisAlignment .end,
221221 children: [
222222 Flexible (child: textContent),
223223 SizedBox (width: 4 ),
224- Padding (
225- padding:
226- timeAndStatusPositionInlineInsets ?? EdgeInsets .zero,
227- child: timeAndStatus,
228- ),
224+ Padding (padding: timeAndStatusPositionInlineInsets ?? EdgeInsets .zero, child: timeAndStatus),
229225 ],
230226 )
231227 : textContent,
232- if (effectiveLinkPreviewPosition == LinkPreviewPosition .bottom)
233- linkPreviewWidget! ,
228+ if (effectiveLinkPreviewPosition == LinkPreviewPosition .bottom) linkPreviewWidget! ,
234229 if (timeAndStatusPosition != TimeAndStatusPosition .inline)
235230 // Ensure the width is not smaller than the timeAndStatus widget
236231 // Ensure the height accounts for it's height
237232 Opacity (opacity: 0 , child: timeAndStatus),
238233 ],
239234 ),
240- if (timeAndStatusPosition != TimeAndStatusPosition .inline &&
241- timeAndStatus != null )
235+ if (timeAndStatusPosition != TimeAndStatusPosition .inline && timeAndStatus != null )
242236 Positioned .directional (
243237 textDirection: textDirection,
244238 end: timeAndStatusPosition == TimeAndStatusPosition .end ? 0 : null ,
245- start:
246- timeAndStatusPosition == TimeAndStatusPosition .start ? 0 : null ,
239+ start: timeAndStatusPosition == TimeAndStatusPosition .start ? 0 : null ,
247240 bottom: 0 ,
248241 child: timeAndStatus,
249242 ),
@@ -262,16 +255,12 @@ class FlyerChatTextMessage extends StatelessWidget {
262255 if (isSentByMe) {
263256 return sentTextStyle ?? theme.bodyMedium.copyWith (color: theme.onPrimary);
264257 }
265- return receivedTextStyle ??
266- theme.bodyMedium.copyWith (color: theme.onSurface);
258+ return receivedTextStyle ?? theme.bodyMedium.copyWith (color: theme.onSurface);
267259 }
268260
269261 TextStyle ? _resolveTimeStyle (bool isSentByMe, _LocalTheme theme) {
270262 if (isSentByMe) {
271- return timeStyle ??
272- theme.labelSmall.copyWith (
273- color: _isOnlyEmoji ? theme.onSurface : theme.onPrimary,
274- );
263+ return timeStyle ?? theme.labelSmall.copyWith (color: _isOnlyEmoji ? theme.onSurface : theme.onPrimary);
275264 }
276265 return timeStyle ?? theme.labelSmall.copyWith (color: theme.onSurface);
277266 }
@@ -312,18 +301,10 @@ class TimeAndStatus extends StatelessWidget {
312301 spacing: 2 ,
313302 mainAxisSize: MainAxisSize .min,
314303 children: [
315- if (showTime && time != null )
316- Text (timeFormat.format (time! .toLocal ()), style: textStyle),
304+ if (showTime && time != null ) Text (timeFormat.format (time! .toLocal ()), style: textStyle),
317305 if (showStatus && status != null )
318306 if (status == MessageStatus .sending)
319- SizedBox (
320- width: 6 ,
321- height: 6 ,
322- child: CircularProgressIndicator (
323- color: textStyle? .color,
324- strokeWidth: 2 ,
325- ),
326- )
307+ SizedBox (width: 6 , height: 6 , child: CircularProgressIndicator (color: textStyle? .color, strokeWidth: 2 ))
327308 else
328309 Icon (getIconForStatus (status! ), color: textStyle? .color, size: 12 ),
329310 ],
0 commit comments