Skip to content

Commit e4a6fa4

Browse files
author
Ephraim Nartey
committed
fix: fallback to url if link preview title is empty
1 parent 0456cb8 commit e4a6fa4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/ui/link_preview.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ class LinkMetadata {
3131
final document = parse(utf8.decode(response.bodyBytes));
3232

3333
// Extract metadata from meta tags
34-
final title = document
34+
String title = document
3535
.querySelector('meta[property="og:title"]')
3636
?.attributes['content'] ??
37-
document.querySelector('title')?.text;
37+
document.querySelector('title')?.text ?? '';
38+
39+
if(title.isEmpty){
40+
//if no title is set fallback to url
41+
title = url;
42+
}
3843

3944
final description = document
4045
.querySelector('meta[property="og:description"]')

0 commit comments

Comments
 (0)