feat: show link URL below post body for news stories
This commit is contained in:
parent
e03442f789
commit
1d05300f17
|
|
@ -2,6 +2,7 @@ import 'dart:ui';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import '../models/post.dart';
|
||||
import '../providers/settings_provider.dart';
|
||||
|
||||
|
|
@ -264,6 +265,23 @@ class _sojornPostCardState extends ConsumerState<sojornPostCard> {
|
|||
),
|
||||
),
|
||||
],
|
||||
// Show link URL below post body for posts with link previews
|
||||
if (post.hasLinkPreview && post.linkPreviewUrl != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
GestureDetector(
|
||||
onTap: () => _launchPreviewUrl(post.linkPreviewUrl!),
|
||||
child: Text(
|
||||
_truncateUrl(post.linkPreviewUrl!),
|
||||
style: TextStyle(
|
||||
color: AppTheme.royalPurple,
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
decoration: TextDecoration.underline,
|
||||
decorationColor: AppTheme.royalPurple.withValues(alpha: 0.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
@ -381,6 +399,27 @@ class _sojornPostCardState extends ConsumerState<sojornPostCard> {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
String _truncateUrl(String url) {
|
||||
if (url.length <= 45) return url;
|
||||
try {
|
||||
final uri = Uri.parse(url);
|
||||
final path = uri.path;
|
||||
if (path.length > 15) {
|
||||
return '${uri.scheme}://${uri.host}${path.substring(0, 12)}...';
|
||||
}
|
||||
return '${uri.scheme}://${uri.host}$path';
|
||||
} catch (_) {
|
||||
return '${url.substring(0, 42)}...';
|
||||
}
|
||||
}
|
||||
|
||||
void _launchPreviewUrl(String url) {
|
||||
final uri = Uri.tryParse(url);
|
||||
if (uri != null) {
|
||||
launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Subtle single-line "replying to" hint shown on feed cards that are chains.
|
||||
|
|
|
|||
Loading…
Reference in a new issue